--創建登錄賬號
create login username with password='password'
--創建數據庫用戶
create user username for login username
---授予該用戶對Student表的查詢權限,同時授予其進一步授權其他用戶的權利。
grant select
on student
to user_tom
with grant option
-----
create login marry with password='marry001'
create user user_marry for login marry
--創建角色
create role dbnormuser
---對角色授權
grant select
on student
to dbnormuser
--指定固定的服務器角色(登錄名)
sp_addsrvrolemember marry,sysadmin
刪除
sp_dropsrvrolemember marry,sysadmin
--查看用戶
sp_helpuser
---新建外鍵約束
ALTER TABLE test_sub ADD CONSTRAINT main_id_cons FOREIGN KEY (main_id) REFERENCES test_main;
---刪除外鍵
ALTER TABLE test_sub drop CONSTRAINT main_id_cons
--創建級聯刪除外鍵
ALTER TABLE test_sub ADD CONSTRAINT main_id_cons FOREIGN KEY (main_id) REFERENCES test_main on delete
cascade
--創建級聯更新外鍵
ALTER TABLE test_sub ADD CONSTRAINT main_id_cons FOREIGN KEY (main_id) REFERENCES test_main on update
cascade
--創建刪除被參照主鍵是 鍵參照關系的外鍵設置為null
ALTER TABLE test_sub ADD CONSTRAINT main_id_cons FOREIGN KEY (main_id) REFERENCES test_main on update
set null
----參照完整性
不能刪除 帶有外鍵的記錄