--创建数据库create database 学生练习on(name = srcShareDB,filename = 'E:\stuExcise.mdf',size = 10,maxsize = unlimited,filegrowth = 10%)--日志文件log on(name = srcShareLG,filename = 'E:\stuExcise.ldf',size = 3,maxsize = unlimited,filegrowth
--创建数据库 create database 学生练习 on ( name = srcShareDB, filename = 'E:\stuExcise.mdf', size = 10, maxsize = unlimited, filegrowth = 10% ) --日志文件 log on ( name = srcShareLG, filename = 'E:\stuExcise.ldf', size = 3, maxsize = unlimited, filegrowth = 10% ) --学生表 create table 学生 ( stuNO varchar(10) primary key, stuAge int check (stuAge>0 and stuAge=0 and lsnMark0 and lsnHour=0 and stuMark
约束规则:
1、实体完整性规则
主要是针对主键(列级和表级)的,主键约束用于唯一性表示表的记录,并且主键约束要求该列不为空,切记是不为NULL而不是不为"",并且要求该列不能有相同项,否则不能执行sql
语句
2、参照完整性约束,即为外键约束,主要是表示表中列和表中列的关系
语法是:foreign key(列名) references 表名(列名),
其中(列名)需加括号,表名(列名)中列名需为所引用表的主键
3、用户自定义完整性约束
包括列值非空(not null),列值唯一(unique),检查列值是否满足一个布尔表达式(check)
需要注意的是check约束需要括号,即check(布尔值)连接的种类:
内联接:分为等值连接和自然连接,通过比较运算符来连接
语法:select * from table1 join table2 on table1.id=table2.id交叉连接:即产生笛卡儿积的连接
语法:select * from table1 cross join table2外连接:
左外连接:返回左表的所有行,右表不匹配的用null表示
语法:select * from table1 left join table2 on table1.id=table2.id右外连接:返回右表的所有行,左表不匹配的用null表示
语法:select * from table1 right join table2 on table1.id=table2.id全连接:返回连接表的所有行
语法:select * from table1 full join table2 on table1.id=table2.id
已抢23343个
抢已抢117769个
抢已抢139233个
抢已抢6233个
抢已抢35543个
抢已抢8114个
抢