SQL Server数据库语法(一)

--创建数据库 DB_CYIT
create database DB_CYIT
ON
(
name='DB_CYIT',--主文件逻辑名称
filename='G:\data\DB_CYIT.mdf', --文件地址
size=5mb,--文件大小
filegrowth=2mb --主文件增长
)
LOG ON
(
name='DB_CYIT_log',--主文件日志逻辑名称
filename='G:\data\DB_CYIT.ldf',--主文件日志地址
size=5mb,--主文件日志大小
filegrowth=2mb --主文件日志增长
)

 

数据完整性(Data Integrity)是指数据的精确性(Accuracy)和可靠性(Reliability)

实体完整性(Entity Integrity)

PRIMARY KEY(主键)约束)

IDENTITY(自增)约束

UNIQUE(唯一)约束

域完整性(Domain Integrity)

CHECK(检查)约束

FOREIGN KEY(外键)约束

DEFAULT(默认值)约束

NOT NULL(非空)约束

引用完整性(Referential Integrity)

用户自定义完整性(User-defined Integrity)

 


--创建新表
create table Tb_Student
(
StudentNo int identity(1,1) primary key,
StudentName varchar(20) not null,
StudentAge int check(StudentAge<30 and StudentAge>20),
Country varchar(20) default'中国',
StuTime datetime not null,
TuitiON money not null,
)

create table Tb_Student_Course
(
SCNo int identity(1,1) primary key,
StudentNo int references Tb_Student(StudentNo),
CourseName varchar(30) unique not null,
CourseTime int not null,
StuTime datetime not null,
Notes varchar(1000)
)

 

posted @ 2019-08-16 18:17  什么都不懂的程序猿  阅读(527)  评论(0编辑  收藏  举报