insert into Person(name) values('wangyang')
drop table Person
//创建Person表,not null表示非空,default 'wang'表示name的默认值
create table Person
(
number int primary key not null,
name varchar(20) default 'wang',
birthday datetime
)
//插入值
insert into Person values(1,'wangyang',1987)
//创建表Work
create table Work
(
name varchar(21),
workNum int,
foreign key(workNum) references Person(number)
)
//向表Person中插入一列sex,bit数据类型表示bool型
alter table Person add sex bit
//删除表Person的birthday列
alter table Person drop birthday
drop table Work
create table T_Person
(
FName varchar(20), //姓名
FAge int, //年龄
FRemark varchar(20), //备注信息
primary key (FName)
);
create table T_Debt //欠债信息表
(
FNumber varchar(20), //债务编号
FAmount decimal(10,2) not null,//欠债金额
FPerson varchar(20), //欠债人姓名
primary key(FNumber),
foreign key (FPerson) references T_Person(FName)
);
insert into T_Person(FName,FAge,FRemark) values('Tom',18,'USA');
insert into T_Person(FName,FAge,FRemark) values('Jim',20,'USA');
insert into T_Person(FName,FAge,FRemark) values('Lili',22,'China');
insert into T_Person(FName,FAge,FRemark) values('XiaoWang',17,'China');
//可以打乱列的顺序,但要和后面对应
insert into T_Person(FAge,FName,FRemark) values(21,'Kimisushi','Korea');
//可以省去某一列的值
insert into T_Person(FAge,FName) values(22,'LXF');
//可以不用指定要插入的列,此时按表的定义插入
insert into T_Person values('luren1',23,'China');
insert into T_Debt(FNumber,FAmount,FPerson) values('1',200,'Jim');
insert into T_Debt(FNumber,FAmount,FPerson) values('2',200,'Jim');
insert into T_Debt(FNumber,FAmount,FPerson) values('3',100,'Tom');
select * from T_Person;
select * from T_Debt;
/*数据的更新,用update*/
update T_Person set FRemark='SuperMan'; //更新某一列
update T_Person set FRemark='Sonic',FAge=25; //更新多个列,多列之间逗号隔开
/*带where子句的update语句*/
update T_Person set FAge=12 where FName='Tom';
update T_Person set FRemark='BlaBla' where FAge=25;
update T_Person set FAge=22 where FName='Jim' or FName = 'Tom';
/*数据的删除*/
/*简单的数据删除*/
delete T_Debt;
delete T_Person;/*由于T_Debt有指向T_Person的外键,所以应先删除T_Debt,在删除T_Person*/
/*delete是将表中的数据删除,表的结构还存在,drop table不仅将表中数据删除,还把表的结构删除了*/
/*带where子句的delete语句*/
delete from T_Person where FAge>20 or FRemark = 'USA';
select * from T_Person;
select * from T_Debt;