MS T-SQL编程例

来源:互联网 发布:java.util包 编辑:程序博客网 时间:2024/06/05 16:25

为复习T-SQL随便写了段

create database book_manage_sys
go
sp_addlogin 
'book_manage_sys_login','89414795'
go
sp_addsrvrolemember 
'book_manage_sys_login','sysadmin'
go
use book_manage_sys
go
create table admin
(账号 
char(20not null primary key,
 密码 
char(20not null default '',
 密保问题 
char(20null default '',
 密保答案 
char(20null default '',
 备注 
text null default ''
)
go
create table employee
(账号 
char(20not null primary key,
 密码 
char(20not null default '',
 密保问题 
char(20null default '',
 密保答案 
char(20null default '',
 备注 
text null default ''
)
go
create table reader_style
(读者类别编号 
char(20not null primary key,
 读者类别名称 
char(20not null,
 借书数量 
int not null,
 借书期限 
int not null,
 有限期限 
int not null,
 备注 
text null default ''
)
go
create table reader_info
(读者编号 
char(20not null primary key,
 读者类别编号 
char(20not null foreign key references reader_style(读者类别编号),
 读者身份证号 
char(20not null unique,
 读者姓名 
char(20not null,
 读者性别 
char(2not null check(读者性别 in('','')) default '',
 读者密码 
char(20not null default '',
 密保问题 
char(20null default '',
 密保答案 
char(20null default '',
 工作单位 
char(50null default '',
 住址 
char(50null default '',
 电话号码 
char(12not null default '',
 email 
char(20null default '',
 登记日期 
datetime not null,
 已借书数量 
int default 0 not null,
 备注 
text null default ''
)
go
create table book_style
(图书类别编号 
char(20not null primary key,
 图书类别名称 
char(20not null,
 备注 
text null default ''
)
go
create table book_info
(图书编号 
char(20not null primary key,
 图书名称 
char(50not null,
 图书类别编号 
char(20not null foreign key references book_style(图书类别编号),
 ISBN 
char(13not null,
 价格 
int not null,
 作者 
char(20null default '',
 出版社 
char(50null default '',
 出版日期 
datetime null,
 上架日期 
datetime not null,
 在库数 
int not null,
 备注 
text null default ''
)
go
create table lead_info
(借阅编号 
int identity(1,1not null primary key,
 读者编号 
char(20not null foreign key references reader_info(读者编号), 
 读者姓名 
char(20null default '',
 图书编号 
char(20not null foreign key references book_info(图书编号),
 图书名称 
char(50null default '',
 出借日期 
datetime not null,
 还书日期 
datetime null,
 备注 
text null default ''
)
go
create table leave_word
(留言编号 
int identity(1,1not null primary key,
 读者编号 
char(20not null foreign key references reader_info(读者编号),
 留言时间 
datetime not null,
 留言信息 
text null default ''
)
go
sp_addrole 
'finder_book_manage_sys_role'
go
create procedure book_manage_sys_pro
as
grant select on lead_info to finder_book_manage_sys_role
grant select on book_info to finder_book_manage_sys_role
grant select,update on reader_info to finder_book_manage_sys_role
grant select,update on leave_word to finder_book_manage_sys_role
grant select on book_style to finder_book_manage_sys_role
grant select on reader_style to finder_book_manage_sys_role
grant select on booking to finder_book_manage_sys_role
go
exec book_manage_sys_pro
go
sp_addlogin 
'finder_book_manage_sys_login','89414795'
go
sp_grantdbaccess 
'finder_book_manage_sys_login','user'
go
sp_addrolemember 
'finder_book_manage_sys_role','user'
go
insert into admin (账号,密码,密保问题,密保答案)values ('10000','sa','你是谁?','勇不言败')
insert into employee (账号,密码,密保问题,密保答案)values ('00001','sa','你是谁?','勇不言败')
insert into reader_style values('01','学生','4','3','36','')
insert into reader_info (读者编号,读者身份证号,读者姓名,读者类别编号,已借书数量,电话号码,登记日期) values('200318070104','430122198409108414','','01','1','2430058','2004-12-13')
insert into book_style values ('01','计算机','')
insert into book_info values('PT312-1','C#','01','9787030120204','32','金林平','教育','2004-1-2','2004-7-14','1','')
insert into lead_info(读者编号,图书编号,出借日期,备注) values ('200318070104','PT312-1',getdate(),'')
insert into leave_word (读者编号,留言时间,留言信息) values('200318070104',getdate(),'我很喜欢这个系统!')
--sp_droplogin 'finder_book_manage_sys_login'
--
sp_droplogin 'book_manage_sys_login'
原创粉丝点击