jdbc知識問答

1 JDBC連接數據庫6步

Load the JDBC Driver
Establish the Database Connection
Create a Statement Object
Execute a Query
Process the Results
Close the Connection
2 事務的4大特性

答:原子性A,一致性C,隔離性I,永久性D

3.select count(*) from student 和select count(id) from student 之間的區別。

答案:

select count(*) 統計所有學生的記錄個數,包括空記錄。

Select count(Id) 統計所有學生的記錄個數,不包括null記錄。

4假設現在有表system.table1,表中有三個字段:id(數值型)、name(字符型)、age(數值型)寫出SQL語句完成如下功能:在表中查出年齡大於20,且名字以“王”開頭的記錄,並且按照年齡的倒敘排列出來(年齡大的在前面)。

答案:

Select * from system.table1 where age>20 and name like ‘王%’ order by age DESC;

5 .創建CUSTOMERS表,字段爲:ID:(非空,主鍵)bigint,NAME:(非空)varchar,AGE:int類型;創建ORDERS表,字段爲:ID:(非空,主鍵,)bigint,ORDER_NUMBER:(非空)varchar,PRICE:double,CUSTOMER_ID :(外鍵)bigint,設置級連刪除;

答案:create table CUSTOMBERS(

ID bigint not null,

NAME varchar(15),

AGE int,

primary key (ID)

);

create table ORDERS(

ID bigint not null,

ORDER_NUMBER varchar(15) not nulll,

PRICE double precision,

CUSTOMER_ID bigint,

primary key(ID),

);

alter table ORDERS add constraint FK_CUSTOMER foreign key (CUSTOMER_ID) references CUSTOMERS(ID) on delete cascade;

6.使用左外連接查詢,ORDERS 和 CUSTOMERS 表,

答案:select c.ID, o.CUSTOMER_ID,c.NAME, o.ID ORDER_ID,ORDER_NUMBER from CUSTOMERS c left outer join ORDERS o no c.ID=o.CUSTOMER_ID;

29 .簡述數據庫事務的生命週期?(可畫流程圖)

答案:





7.delete from tablea & truncate table tablea的區別

   truncate 語句執行速度快,佔資源少,並且只記錄頁刪除的日誌;

   delete 對每條記錄的刪除均需要記錄日誌
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章