// 1. dbms 登入帳號管理
create login sqluser with password = 'pswdforuser_1'
create login sqluser2 with password = 'pswdforuser_123'
create login uselessuser with password = 'useless_123'
alter login sqluser with name = sqluser1
alter login sqluser2 with password = 'pswdforuser_2'
drop login uselessuser
// 2. 資料庫使用者管理
use mobilephone
create
user sqluser1 with default_schema=dbo
create
user sqluser2
drop
user sqluser2
create
user db_user for login sqluser2 with default_schema=dbo
// 3. 對資料庫使用者進行許可權/收回許可權
use mobilephone
grant
select, update(cname)
on company
to sqluser1
with
grant
option
grant
select
on phone
topublic
grant
allprivileges
on operatingsystem
to db_user
grant
alter
onschema::dbo to sqluser1
grant
create
view, create
procedure, backup database
to sqluser1, db_user
revoke
insert, delete
on operatingsystem
from db_user
revoke
create
table
from sqluser1, db_user
deny create
view
to db_user
// 4. 建立角色,為角色分配使用者及許可權
create role updator
authorization sqluser1
create role deleter
authorization db_user
exec sp_addrolemember 'deleter', 'sqluser1'
create role theotherrole
authorization sqluser1
grant
update
on phone to updator
grant
delete
on phone to deleter
exec sp_addrolemember 'updator', db_user
drop role theotherrole
//1. 儲存過程的建立、執行與管理
create proc phonecount
@osname char(20),
@cnt int
output
asselect @cnt = count(phonename)
from phone
where os = @osname
declare @cnt int
exec phonecount 'ios', @cnt output
print @cnt
alter
procedure phonecount
@introduced_year int,
@cnt int
output
asselect @cnt = count(phonename)
from phone
where introducedyear = @introduced_year
drop
procedure phonecount
declare @cnt int
exec phonecount 2014, @cnt output
print @cnt
drop proc phonecount
//2. 觸發器的建立與管理
create
trigger tri_newphone
on phone instead of
insert
asif
notexists(
select * from inserted
where introducedyear > year(getdate())
)insert
into phone select * from inserted
else print '不得插入今年未上市的手機'
drop
trigger tri_newphone
insert
into phone
select * from phone
create
trigger tri_notphone
on phone after
insert
asif
exists(
select * from phone
where displaysize not between 1.0
and6.2
)rollback
drop
trigger tri_notphone
//1. 對所建立的資料庫進行完整、差異、日誌備份
exec sp_addumpdevice 'disk', 'mobilephonebak', 'c:\program files\microsoft sql server\mssql10_50.mssqlserver\mssql\backup\mp.bak'
backup database mobilephone
to mobilephonebak with init
backup database mobilephone
to mobilephonebak with differential
backup log mobilephone to disk='c:\program files\microsoft sql server\mssql10_50.mssqlserver\mssql\backup\mplog.dat'
use master
backup log mobilephone to disk='c:\program files\microsoft sql server\mssql10_50.mssqlserver\mssql\backup\mplog.dat'
with norecovery
//2. 資料庫恢復
backup log mobilephone to disk='c:\program files\microsoft sql server\mssql10_50.mssqlserver\mssql\backup\mplog.dat'
with norecovery
restore database mobilephone
from mobilephonebak with file=1
backup log mobilephone to disk='c:\program files\microsoft sql server\mssql10_50.mssqlserver\mssql\backup\mplog2.dat'
with norecovery
restore database mobilephone
from mobilephonebak with file=1, norecovery
restore database mobilephone
from mobilephonebak with file=2
資料庫(實驗2 資料庫表)
建立資料庫 建立資料庫資料檔案 create database testbase2 on name testbase2 data,filename d 張小山資料庫 lianxi2 testbase2 data.mdf size 5mb,maxsize 50mb,filegrowth 20 建立資料...
南郵資料庫實驗2 小型資料庫設計
題目 自己設計乙個小型資料庫。個人比較喜歡看電影,於是用python爬了豆瓣top250的電影,做了乙個關於電影的小型資料庫,這裡只舉一小部分作為例子。關係模式 電影名稱關係模式 title mno,mname 電影評分關係模式 rating mno,mscore 電影標籤關係模式 tag mno,...
DB2實驗 資料庫恢復
實驗九 資料庫恢復 實驗內容 第 1 節 決定db2目前的日誌配置引數第2 節 迴圈日誌條件下的資料庫恢復第3 節 歸檔日誌條件下的資料庫恢復 注意 1 實驗用到的資料在db2 lab data資料夾下的cf23中 2 在實驗過程中,可以用嚮導來完成實驗,但請大家注意記錄嚮導操作相應的sql語句。第...