create database mydb1
on (
name=test,
filename ='d:\t.mdf'
)
log on(
name =t,
filename='d:\test.ldf'
)
use mydb1
create table test(
name varchar(20),
id int,
addr varchar(20),
)
sp_help test
select * from test;
alter table test alter column id varchar(10) NOT NULL
alter table test add constraint t primary key (id)
create table test2(
id int primary key,
name varchar(23)
)
sp_help test2
drop table test2
alter table test add sex varchar(2);
sp_help test
alter table test add constraint t1 check(sex='妖怪')
select * from test
alter table test alter column sex varchar(10)
create database YGGL on
(
name=YGGL,
filename='D:\SQL2\YGGL.mdf'
)
log on (
name=YGGLdf,
filename='D:\SQL2\YGGL.ldf'
)
use YGGL
create table 员工信息表(
员工编号 int primary key,--数字 主键
员工姓名 varchar(20) not null,--字符 不能为空
员工性别 bit,--布尔
出生日期 datetime,--日期
个人简介 text,--文本
)
sp_help 员工信息表
create table 考核项目表(
项目编号 varchar(20),--字符
项目名称 varchar(20),--字符 不能为空
项目类型 varchar(4) constraint t1 check(项目类型='惩罚' or 项目类型='奖励'),--字符 只能是(惩罚,奖励)
)
create table 考核信息表 (
考核编号 int identity(1,1),--数字 自增长
考核项目编号 int not null,--数字 不能为空
员工编号 int not null,--数字 不能为空
考核信息 varchar(10),-- 字符(10)
考核备注 varchar(30),--字符(30)
考核日期 datetime default(getdate()),--日期默认当前
)
alter table 员工信息表 add 员工电话 bigint
alter table 员工信息表 drop column 个人简介
alter table 考核项目表 alter column 项目编号 varchar(20) not null--将字段设为不为空
alter table 考核项目表 add constraint t2 primary key (项目编号)--加入主键约束
alter table 考核项目表 alter column 项目类型 varchar(4) not null
alter table 考核信息表 alter column 考核项目编号 varchar(2)
alter table 考核信息表 alter column 考核信息 nvarchar(20)
alter table 员工信息表 add 照片 image
alter table 考核信息表 add 考核金额 money
alter table 员工信息表 add constraint t3 unique(员工电话)--设置唯一
create table 员工工资表 (
自动编号 int identity(1,1),
员工编号 int foreign key references 员工信息表 ,
基本工资 int,
工资系数 decimal(2,1) check (工资系数>=6.0 and 工资系数<=1.0),--(1.0到6.0之间的小数)
发工资日期 datetime default(getdate()),--默认当前
应发工资 int default(),--=基本工资*工资系数
)最后怎么做
on (
name=test,
filename ='d:\t.mdf'
)
log on(
name =t,
filename='d:\test.ldf'
)
use mydb1
create table test(
name varchar(20),
id int,
addr varchar(20),
)
sp_help test
select * from test;
alter table test alter column id varchar(10) NOT NULL
alter table test add constraint t primary key (id)
create table test2(
id int primary key,
name varchar(23)
)
sp_help test2
drop table test2
alter table test add sex varchar(2);
sp_help test
alter table test add constraint t1 check(sex='妖怪')
select * from test
alter table test alter column sex varchar(10)
create database YGGL on
(
name=YGGL,
filename='D:\SQL2\YGGL.mdf'
)
log on (
name=YGGLdf,
filename='D:\SQL2\YGGL.ldf'
)
use YGGL
create table 员工信息表(
员工编号 int primary key,--数字 主键
员工姓名 varchar(20) not null,--字符 不能为空
员工性别 bit,--布尔
出生日期 datetime,--日期
个人简介 text,--文本
)
sp_help 员工信息表
create table 考核项目表(
项目编号 varchar(20),--字符
项目名称 varchar(20),--字符 不能为空
项目类型 varchar(4) constraint t1 check(项目类型='惩罚' or 项目类型='奖励'),--字符 只能是(惩罚,奖励)
)
create table 考核信息表 (
考核编号 int identity(1,1),--数字 自增长
考核项目编号 int not null,--数字 不能为空
员工编号 int not null,--数字 不能为空
考核信息 varchar(10),-- 字符(10)
考核备注 varchar(30),--字符(30)
考核日期 datetime default(getdate()),--日期默认当前
)
alter table 员工信息表 add 员工电话 bigint
alter table 员工信息表 drop column 个人简介
alter table 考核项目表 alter column 项目编号 varchar(20) not null--将字段设为不为空
alter table 考核项目表 add constraint t2 primary key (项目编号)--加入主键约束
alter table 考核项目表 alter column 项目类型 varchar(4) not null
alter table 考核信息表 alter column 考核项目编号 varchar(2)
alter table 考核信息表 alter column 考核信息 nvarchar(20)
alter table 员工信息表 add 照片 image
alter table 考核信息表 add 考核金额 money
alter table 员工信息表 add constraint t3 unique(员工电话)--设置唯一
create table 员工工资表 (
自动编号 int identity(1,1),
员工编号 int foreign key references 员工信息表 ,
基本工资 int,
工资系数 decimal(2,1) check (工资系数>=6.0 and 工资系数<=1.0),--(1.0到6.0之间的小数)
发工资日期 datetime default(getdate()),--默认当前
应发工资 int default(),--=基本工资*工资系数
)最后怎么做