create table people ( Code Varchar(50) primary key, Name Varchar (30) not null, Time date, Age int, Nation varchar(50) references Nation2(Code) ); create table Nation2 ( Code varchar(50) primary key, Name varchar(50) not null ) create table Race ( Code varchar(50) primary key,#注意不能设为自增长因为自增长必须为整形,否则报错 Name varchar (50) ) 添加数据: insert into Nation2 values(‘001‘,‘汉族‘); insert into Nation2 values (‘002‘,‘回族‘); insert into Nation2 values( ‘003‘,‘苗族‘); insert into Nation2 values(‘004‘,‘壮族‘); insert into Nation2 (Code) values(‘005‘); insert into Nation2 (Name)values(‘蒙古族‘); insert into Nation2 (Code) values(‘006‘);#多次试验发现Code带主键的可以多次单个添加code但name 只能第一次添加一个,再添加就报错。或者删了这个在添加也报错 delete from Nation2 where Code=003;#删除 单个数据 delete from Race #删除整个数据 select*from people#查询people所有数据 select*from Nation2 where Code=4 #根据条件查询 drop table Nation2 #删除整张表 update Nation2 set Name=‘维吾尔族‘where code=003;#修改某个数据 update people set Name=‘李四‘,Time=‘2000-06-03‘,Age=‘16‘,Nation=‘回族‘ where Code=001;# 修改时一定注意最后一个不能加逗号
时间: 2024-12-21 16:12:38