sql

CreateDatabase
create database my2017
go
use my2017
go
create table Department -- 大科室
(
DeptNo char ( 6 ) not null,
DeptName varchar ( 50 ) not null,
constraint PK_Department primary key ( DeptNo )
)
create table [Group] -- 小科室
(
GroupNo char ( 4 ) not null,
GroupName varchar ( 50 ) not null,
DeptNo char ( 6 ) not null,
[Month] char ( 2 ),
Number int check ( Number <= 80 ),
constraint PK_Group primary key ( GroupNo ),
constraint FK_Group_Department foreign key ( DeptNo ) references Department ( DeptNo )
)
create table Patient -- 病人
(
PID char ( 14 ) not null,
PName varchar ( 50 ) not null,
[Date] datetime default(getdate()) ,
GroupNo char ( 4 ) not null,
constraint PK_Patient primary key ( PID ),
constraint FK_Patient_Group foreign key ( GroupNo ) references [Group] ( GroupNo ) on delete cascade
)
insert into Department values ( '111' , ' 内科 ' )
insert into Department values ( '222' , ' 外科 ' )
insert into Department values ( '333' , ' 骨科 ' )
go
insert into [Group] values ( '11' , ' 呼吸科 ' , '111' , '3' , 68 )
insert into [Group] values ( '12' , ' 心内科 ' , '111' , '4' , 43 )
insert into [Group] values ( '13' , ' 胸外科 ' , '222' , '3' , 52 )
insert into [Group] values ( '14' , ' 骨外科 ' , '333' , '3' , 28 )
insert into [Group] values ( '15' , ' 外伤科 ' , '222' , '4' , 39 )
go
insert into Patient values ( '8801101' , ' 李一 ' , '1987-2-18' , '11' )
insert into Patient values ( '8801102' , ' 王二 ' , '1995-5-12' , '13' )
insert into Patient values ( '8801103' , ' 张三 ' , '1988-10-24' , '14' )
insert into Patient values ( '8801104' , ' 邓四 ' , '1992-7-3' , '12' )
insert into Patient values ( '8801105' , ' 刘五 ' , '1985-4-25' , '14' )
insert into Patient values ( '8801106' , ' 赵六 ' , '1982-6-30' , '11' )
insert into Patient values ( '8801107' , ' 陈七 ' , '1994-1-11' , '12' )
insert into Patient values ( '8801108' , ' 周八 ' , '2000-3-13' , '11' )
go

--创建索引
create index idx_ordername on Orders ( OrderName )
go
--创建视图
create view vw_statistics
as
select ProductID , SUM ( Quantity ) 销售数量 , SUM ( Quantity * UnitPrice ) 金额
from OrderDetails
group by ProductID
go

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值