查看表结构
desc stu6;
insert into stu6(id,name ,sex) values(1,‘zsf‘,‘nv‘);
insert into stu6(id,name) values(2,‘zsf‘);
查询结构:
select * from stu6;
###引用完整性
学生表
id
名字
性别
成绩表
id
学生ID
成绩
create table stu7(
id int primary key,
name varchar(50)
);
create table score(
id int primary key,
sid int,
score double,
constraint aa foreign key(sid) references stu7(id)
)
insert into stu7(id,name) values(1,‘zsf‘);
insert into score(id,sid,score) values(1,1,90);
ERROR 1452 (23000): Cannot add or update a child
row: a foreign key constraint fails (`db`.`score`,
CONSTRAINT `aa` FOREIGN KEY (`sid`) REFERENCES `stu7` (`id`))
##合并结果集
create table t1(
id int,
name varchar(10)
)
##插入数据
insert into t1 values(1,‘zs‘),(2,‘ls‘);
create table t2(
id int,
name varchar(10)
)
##插入数据
insert into t2 values(1,‘zs‘),(2,‘ls‘);
insert into t2 values(3,‘zs‘),(4,‘ls‘);
##t1表的数据
select * from t1;
+------+------+
| id | name |
+------+------+
| 1 | zs |
| 2 | ls |
+------+------+
#t2表的数据
select * from t2;
+------+------+
| id | name |
+------+------+
| 1 | zs |
| 2 | ls |
| 3 | zs |
| 4 | ls |
+------+------+
##对t1,t2的结果进行合并
select * from t1
union all
select * from t2;
select * from t1
union
select * from t2;
+------+------+
| id | name |
+------+------+
| 1 | zs |
| 2 | ls |
| 1 | zs |
| 2 | ls |
| 3 | zs |
| 4 | ls |
+------+------+