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 对每条记录的删除均需要记录日志