建表

建表

learn/sql
SQL
1
2
3
4
5
6
7
8
9
create table Department
(
--部门编号 primary key 主键, identity(1,1)自动增长,初始值 1,增长步长 1
DepartmentId int primary key identity(1,1),
--部门名称
DepartmentIdName nvarchar(50) not null,
--部门描述
DepartmentRemark text
)

-char:定长,char(10),无论存储数据是否真的到了 10 个字节,都要占用 10 个字节。 —char(10)存储’ab,仍然占用 10 个字节-varchar:变长,varchar(10),最多占用 10 个字节。 —varihar(10)存储’ab’,占用 2 个字节

—员工

SQL
1
2
3
4
5
6
7
8
9
10
11
creat table People
(
PeopleId int primary key identity(1,1), --员工编号
DepartmentId int refernces Department(DepartmentId) not null --部门(引用外键)
RankId int references [Rank](RankId) not null --职级
PeopleName nvarchar(50) not null, --姓名
PeopleSex nvachar(1)default('男')check(PeopleSex = '男' or PeopleSex = '女') --性别
PeopleBirth smalldatetime not null , --生日
PeopleSalary decimal(12,2)check(PeopleSalary > 1000 and PeopleSalart <+ 100000) not null ,--月薪
PeopleAddTime smalldatetime default(getdate) --添加时间
)