Sql Server创建数据库和表

创建数据库
USE master
GO
CREATE DATABASE EmployeeSystem--创建员工管理系统数据库
on
(
NAME='EmployeeSystem_data',--主文件逻辑文件名
FILENAME='D:\员工管理系统\EmployeeSystem_data.mdf', --主文件文件名
SIZE=5mb,--系统默认创建的时候会给主文件分配初始大小
MAXSIZE=200MB,--主文件的最大值
filegrowth=5-- 主文件的增长幅度
)
LOG ON
(
name='EmployeeSystem_log',--日志文件逻辑文件名
filename='D:\员工管理系统\EmployeeSystem_log.ldf',--日志文件屋里文件名
SIZE=5MB,--日志文件初始大小
MAXSIZE=100MB,--主文件的最大值
filegrowth=2 --启动自动增长
)
go

创建表
use EmployeeSystem
go
create table EmployeeBaseData--创建员工基础资料表
(
EmployeeID int identity(1,1) not null,--员工ID号
EmployeeName varchar(15) not null,--员工姓名
Gender char(2) not null,--员工姓别
DateOfBirth date not null,--出生日期
CorporationID int not null,--所属公司ID号
constraint PK_EmployeeID primary key clustered(EmployeeID),--设置员工ID为主键,聚集索引
--constraint PK_struent primary key clustered(SNO,BookID) --设置多个主键,设置SNO,BookID为主键
constraint UQ_EmployeeName Unique NONClusterEd(EmployeeName),--设置员工姓名为唯一键,非聚集索引
constraint C_Gender Check (Gender in('男','女')),--约束
constraint FK_CorporationID Foreign key (CorporationID) References Corporation(CorporationID),--设置外键,关连Corporation(CorporationID),关连表的字段必须是主键或唯一键
)
go

猜你喜欢

转载自www.cnblogs.com/zhujie-com/p/12319165.html