if exists(
select
*
from
sysobjects
where
name
=
'ConstructionDB'
)
drop
DATABASE
ConstructionDB
Create
database
ConstructionDB
on
(
name
=
'ConstructionDB_date'
,
filename=
'E:\技能抽查试题第二模块(数据库)\试题——1\任务一\ConstructionDB_date.mdf'
,
size
=3mb,
maxsize=10mb,
filegrowth=5%
)
log
on
(
name
=
'ConstructionDB_log'
,
filename=
'E:\技能抽查试题第二模块(数据库)\试题——1\任务一\ConstructionDB_date.ldf'
,
size
=2mb,
maxsize=5mb,
filegrowth=1mb
)
use ConstructionDB
go
if exists(
select
*
from
sysobjects
where
name
=
'T_flow_step_def'
)
drop
table
T_flow_step_def
IF OBJECT_ID (N
'bas_CardType'
)
IS
NULL
BEGIN
create
table
T_flow_step_def(
Step_no
int
not
null
,
Step_name
varchar
(30)
not
null
,
Step_des
varchar
(64)
not
null
,
Limit_time
int
not
null
,
URL
varchar
(64)
not
null
,
备注
varchar
(256)
not
null
,
)
create
table
T_flow_type(
Flow_type_id
char
(3)
not
null
,
Flow_type_name
varchar
(64)
not
null
,
In_method_id
char
(3)
not
null
,
In_choice_id
char
(3)
not
null
,
备注
varchar
(256)
not
null
,
)
create
table
T_sub_project(
Project_id
varchar
(32)
not
null
,
Sub_pro_id
char
(2)
not
null
,
Flow_type_id
char
(3)
not
null
,
Sub_pro_name
varchar
(64)
not
null
,
Usb_no
varchar
(64)
not
null
,
In_method_id
char
(3)
not
null
,
In_scope_id
char
(3)
not
null
,
In_choice_id
char
(3)
not
null
,
Proj_type_id
char
(3)
not
null
,
Engi_type_id
char
(1)
not
null
,
Pack_type
char
(1)
not
null
,
Grade_type_idv
char
(1)
not
null
,
Flag_done
char
(1)
not
null
,
Flag_forcebreak
char
(1)
not
null
,
备注
varchar
(256)
not
null
,
)
create
database
sql_test
go
use sql_test
go
create
table
学生
(学生编号
char
(4)
primary
key
, 学生名字
varchar
(50)
not
null
)
go
alter
table
学生
add
班级编号
char
(4)
null
go
create
table
班级
(班级编号
char
(4)
primary
key
,班级名称
varchar
(50)
not
null
)
go
create
table
课程
(课程编号
char
(4)
primary
key
,课程名称
varchar
(50)
not
null
,开课日期 datetime )
go
alter
table
课程
add
课程代号
varchar
(10)
null
go
alter
table
课程
drop
column
开课日期
go
alter
table
课程
alter
column
课程名称
varchar
(20)
not
null
go
create
table
product_test_one
(
id
char
(10)
not
null
,
name
varchar
(20)
null
, price money
default
20.5,quantity
smallint
null
,
constraint
pk_id
primary
key
clustered (id)
)
go
create
table
product_test_two
(
id
char
(10)
not
null
,
name
varchar
(20)
null
, price money
default
20.5,quantity
smallint
null
constraint
pk_id2
primary
key
clustered (id)
)
go
drop
table
product_test_one
go
create
table
student
(
id
char
(8),
name
char
(10)
constraint
pk_id
primary
key
(id),
constraint
uk_name
unique
(
name
)
)
go
create
table
student4
(
id
char
(8),
name
char
(10)
constraint
pk_id4
primary
key
(id),
constraint
uk_name4
unique
(
name
)
)
go
drop
table
student4
go
create
table
student3
(
id
char
(8),
name
char
(10),
constraint
pk_id3
primary
key
(id) ,
constraint
uk_name3
unique
(
name
)
)
go
drop
table
student3
go
create
table
员工
(
id
char
(5),
name
char
(20),sex
char
(2),phone
int
constraint
pk_zid
primary
key
(id),
constraint
chk_sex
check
(sex
in
(‘f‘,‘m‘) ),
constraint
chk_phone
check
(phone
like
‘(010) [0-9] [0-9] [0-9] [0-9] [0-9] [0-9] [0-9]‘)
)
go
create
table
默认约束
(
id
char
(5)
primary
key
,sex
varchar
(2)
constraint
con_sex
default
‘m‘
)
go
alter
table
默认约束
add
name
varchar
(10)
null
constraint
con_name
default
‘你好宝贝‘
go
insert
into
班级
values
(‘bj01‘,‘一班‘)
insert
into
班级
values
(‘bj02‘,‘二班‘)
insert
into
班级
values
(‘bj03‘,‘三班‘)
insert
into
班级
values
(‘bj04‘,‘四班‘)
insert
into
班级
values
(‘bj05‘,‘五班‘)
insert
into
班级
values
(‘bj06‘,‘六班‘)
insert
into
班级
values
(‘bj07‘,‘七班‘)
insert
into
班级
values
(‘bj08‘,‘八班‘)
go
select
*
from
班级
go
delete
from
班级
where
班级编号>‘bj06‘
go
select
*
from
班级
go
insert
into
学生
values
(‘xs01‘,‘one‘,‘bj01‘)
insert
into
学生
values
(‘xs02‘,‘two‘,‘bj01‘)
insert
into
学生
values
(‘xs03‘,‘three‘,‘bj01‘)
insert
into
学生
values
(‘xs04‘,‘four‘,‘bj02‘)
insert
into
学生
values
(‘xs05‘,‘five‘,‘bj03‘)
insert
into
学生
values
(‘xs06‘,‘six‘,‘bj02‘)
insert
into
学生
values
(‘xs07‘,‘seven‘,‘bj04‘)
insert
into
学生
values
(‘xs08‘,‘eight‘,‘bj03‘)
insert
into
学生
values
(‘xs09‘,‘nine‘,‘bj04‘)
insert
into
学生
values
(‘xs10‘,‘ten‘,‘bj05‘)
insert
into
学生
values
(‘xs11‘,‘eleven‘,‘bj06‘)
insert
into
学生
values
(‘xs12‘,‘twleve‘,‘bj06‘)
go
select
*
from
学生
go
select
*
from
学生,班级
where
学生.班级编号=班级.班级编号
go
select
学生.学生编号,班级.班级编号, 学生.学生名字,班级.班级名称
from
学生,班级
where
学生.班级编号=班级.班级编号
go
select
*
from
学生
where
班级编号
in
(
select
班级编号
from
班级
where
班级编号=‘bj01‘)
go
select
a.学生编号,a.学生名字,a.班级编号
from
学生
as
a ,班级
as
b
where
a.班级编号=b.班级编号
and
b.班级编号=‘bj01‘
go
select
count
(学生编号)
as
学生统计
from
学生
where
班级编号
in
(
select
班级编号
from
班级
where
班级编号=‘bj01‘)
go
select
count
(学生编号)
as
学生统计, 学生名字,班级编号
from
学生
where
班级编号
in
(
select
班级编号
from
班级
where
班级编号=‘bj01‘)
group
by
班级编号,学生名字
go