library資料庫
create database library
on primary
(name='library_1',
filename='C:\data\library_1.mdf',
size=5MB,
maxsize=30MB,
filegrowth=15%)
log on
(name='library_2',
filename='C:\data\library_1.ldf',
size=3MB,
maxsize=20MB,
filegrowth=15%)
use library
create table readernote
(readerno char(5) not null primary key,
unit varchar(20) not null,
name varchar(8) not null,
sex char(2) not null,
job varchar(8),
address varchar(20) not null)
insert into readernote values('00001','學校','張3','男','主任')
insert into readernote values('00002','學校','李四','男','學生',')
insert into readernote values('00003','學校','王5','女','主任')
insert into readernote values('00004','學校','趙6','男','教師')
insert into readernote values('00005','學校','徐7','女','教師')
create table book
(bookno char(8) not null primary key,
classno char(5) not null,
bookname varchar(20) not null,
author varchar(8) not null,
cbunit varchar(20) not null,
price int not null)
insert into book values('00000001','00001','計算機網路','張平','清華大學出版社',38)
insert into book values('00000002','00002','計算機組成原理','章江','清華大學出版社',35)
insert into book values('00000003','00003','計算機語言','李明','清華大學出版社',50)
insert into book values('00000004','00004','資料庫設計','劉陽','清華大學出版社',32)
insert into book values('00000005','00005','專業英語','李冬','清華大學出版社',22)
create table borrow
(readerno char(5) not null,
bookno char(8) not null,
borrowdatetime datetime not null,
returndatetime datetime not null,
primary key(readerno,bookno),
foreign key(readerno)references readernote(readerno),
foreign key(bookno)references book(bookno))
insert into borrow values('00001','00000001','2011-01-02','2011-02-01')
insert into borrow values('00002','00000002','2011-02-02','2011-03-01')
insert into borrow values('00003','00000003','2011-03-02','2011-04-01')
insert into borrow values('00004','00000004','2011-04-02','2011-05-01')
insert into borrow values('00005','00000005','2011-05-02','2011-06-01')
create table librarymanager
(jobno char(3) not null primary key,
name varchar(8) not null,
sex char(2) not null,
borndatetime datetime not null,
jobname varchar(10) not null,
salary int not null)
insert into librarymanager values('001','姜某','男','1963-09-11','主任',2000)
insert into librarymanager values('002','王某','女','1964-09-11','副主任',1800)
insert into librarymanager values('003','陳某','男','1980-09-11','管理員',1500)
create login mylogin2
with password='password',
check_policy=off
create user sysadmin for login mylogin2
exec sp_addrolemember 'db_owner','sysadmin'
grant all privileges on dbo.readernote to sysadmin
with grant option
grant all privileges on dbo.borrow to sysadmin
with grant option
grant all privileges on dbo.book to sysadmin
with grant option
grant all privileges on dbo.librarymanager to sysadmin
with grant option
create login mylogin3
with password='password',
check_policy=off
create user admin1 for login mylogin3
exec sp_addrolemember 'db_owner','admin1'
create login mylogin4
with password='password',
check_policy=off
create user admin2 for login mylogin4
exec sp_addrolemember 'db_datareader','admin2'grant all privileges on dbo.readernote to admin1
grant all privileges on dbo.borrow to admin1
grant all privileges on dbo.book to admin1
revoke alter on librarymanager from admin1
grant select on borrow to admin2
create procere st
@jobno int
As select * from librarymanager
Where jobno=@jobno
Create procere st1
@readerno int
As select * from borrow
Where readerno=@readerno
Grant exec on st to admin1
Grant exec on st1 to admin2
exec st @jobno=01
exec st1 @readerno=00001
select * from book
應該比較接近了。你自己再改改