MS T-SQL编程例

为复习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 ( 20 not   null   primary   key ,
 密码 
char ( 20 not   null   default   '' ,
 密保问题 
char ( 20 null   default   '' ,
 密保答案 
char ( 20 null   default   '' ,
 备注 
text   null   default   ''
)
go
create   table  employee
(账号 
char ( 20 not   null   primary   key ,
 密码 
char ( 20 not   null   default   '' ,
 密保问题 
char ( 20 null   default   '' ,
 密保答案 
char ( 20 null   default   '' ,
 备注 
text   null   default   ''
)
go
create   table  reader_style
(读者类别编号 
char ( 20 not   null   primary   key ,
 读者类别名称 
char ( 20 not   null ,
 借书数量 
int   not   null ,
 借书期限 
int   not   null ,
 有限期限 
int   not   null ,
 备注 
text   null   default   ''
)
go
create   table  reader_info
(读者编号 
char ( 20 not   null   primary   key ,
 读者类别编号 
char ( 20 not   null   foreign   key   references  reader_style(读者类别编号),
 读者身份证号 
char ( 20 not   null   unique ,
 读者姓名 
char ( 20 not   null ,
 读者性别 
char ( 2 not   null   check (读者性别  in ( ' ' , ' ' ))  default   ' ' ,
 读者密码 
char ( 20 not   null   default   '' ,
 密保问题 
char ( 20 null   default   '' ,
 密保答案 
char ( 20 null   default   '' ,
 工作单位 
char ( 50 null   default   '' ,
 住址 
char ( 50 null   default   '' ,
 电话号码 
char ( 12 not   null   default   '' ,
 email 
char ( 20 null   default   '' ,
 登记日期 
datetime   not   null ,
 已借书数量 
int   default   0   not   null ,
 备注 
text   null   default   ''
)
go
create   table  book_style
(图书类别编号 
char ( 20 not   null   primary   key ,
 图书类别名称 
char ( 20 not   null ,
 备注 
text   null   default   ''
)
go
create   table  book_info
(图书编号 
char ( 20 not   null   primary   key ,
 图书名称 
char ( 50 not   null ,
 图书类别编号 
char ( 20 not   null   foreign   key   references  book_style(图书类别编号),
 ISBN 
char ( 13 not   null ,
 价格 
int   not   null ,
 作者 
char ( 20 null   default   '' ,
 出版社 
char ( 50 null   default   '' ,
 出版日期 
datetime   null ,
 上架日期 
datetime   not   null ,
 在库数 
int   not   null ,
 备注 
text   null   default   ''
)
go
create   table  lead_info
(借阅编号 
int   identity ( 1 , 1 not   null   primary   key ,
 读者编号 
char ( 20 not   null   foreign   key   references  reader_info(读者编号), 
 读者姓名 
char ( 20 null   default   '' ,
 图书编号 
char ( 20 not   null   foreign   key   references  book_info(图书编号),
 图书名称 
char ( 50 null   default   '' ,
 出借日期 
datetime   not   null ,
 还书日期 
datetime   null ,
 备注 
text   null   default   ''
)
go
create   table  leave_word
(留言编号 
int   identity ( 1 , 1 not   null   primary   key ,
 读者编号 
char ( 20 not   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'
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值