1 create table Person #新建表格 2 ( 3 Ids int auto_increment primary key, #主键,自增 4 Name varchar(50) not null, #非空 5 Age int, 6 Sex bit, 7 Nation varchar(50) references Nation(Code) #外键 8 ); 9 create table Person_1 #新建表格 10 ( 11 Ids int auto_increment primary key, 12 Name varchar(50) not null, 13 Age int, 14 Sex bit, 15 Nation varchar(50) references Nation(Code) 16 ); 17 create table Nation #新建表格 18 ( 19 Code varchar(50) primary key, 20 Name varchar(50) 21 ); 22 23 drop table Person_1;#删除表格 24 25 #增加加数据 insert into 表名[(列)] values(数据.对应,可为空) 26 27 insert into Person values('','张三',18,1,'汉族'); 28 insert into Person values('','李四',28,2,'回族'); 29 insert into Person values('','李五',28,2,'回族'); 30 insert into Person(Name) values('王五'); 31 insert into Nation values('001','汉族'); 32 insert into Nation values('002','回族'); 33 34 #删除数据 delete from 表名;删除整个表 35 #delete from 表名 where 条件 36 #delete form Person where Ids=3; 37 38 #更改数据 update 表名 set 列 = "" where 条件; 39 update Person set Name="张八" where Ids=2; 40 update Person set Nation="维吾尔族" where Name="王五"; 41 42 #查找数据 43 select * from Person; 44 select * from Nation where Code='002'; 45 46 delete from Person where name="李五"; 47 48 ################################################# 49 #新建表 50 create table Family 51 ( 52 Name varchar(50) not null, 53 Number int, 54 Code varchar(50) primary key, 55 Color varchar(50) references Color(Code) 56 ); 57 create table Color 58 ( 59 Code int auto_increment primary key, 60 Name varchar(50) 61 ); 62 #CRUD 63 #insert into 表名 values(数据), 64 #insert into 表名(列) values(数据), 65 insert into Family values('1户',4,'001','red'); 66 insert into Family values('2户',3,'002','0002'); 67 insert into Family values('4户',3,'003','0002'); 68 insert into Family(Code) values('004'); 69 insert into Family(Name) values('3户'); 70 insert into Color values('','red'); 71 insert into Color values('','blue'); 72 insert into Color values('','blue'); 73 74 #update 75 #update Table_Name set Cols_Name='' where Condition 76 update Family set Color='white' where Code='001'; 77 78 #delete 79 #delete from Table_Name; 80 #delete from Table_Name where Condition; 81 delete from Family where Name='4户'; 82 delete from Color where Code='3'; 83 84 #select 85 #select * from Table_Name; 86 #select * from Table_Name where Condition; 87 88 select * from Family ; 89 select * from Color where Code='2'