默認架構將是服務器爲此數據庫用戶解析對象名時將搜索的第一個架構。 除非另外指定,不然默認架構將是此數據庫用戶建立的對象所屬的架構。數據庫
若是用戶具備默認架構,則將使用默認架構。 若是用戶不具備默認架構,但該用戶是具備默認架構的組的成員,則將使用該組的默認架構。 若是用戶不具備默認架構並且是多個組的成員,則該用戶的默認架構將是具備最低 principle_id 的 Windows 組的架構和一個顯式設置的默認架構。 若是不能爲用戶肯定默認架構,則將使用 dbo 架構。安全
能夠將 DEFAULT_SCHEMA 設置爲數據庫中當前不存在的架構。 所以,能夠在建立架構以前將 DEFAULT_SCHEMA 分配給用戶。bash
不能爲映射到證書或非對稱密鑰的用戶指定 DEFAULT_SCHEMA。服務器
若是用戶是 sysadmin 固定服務器角色的成員,則忽略 DEFAULT_SCHEMA 的值。 sysadmin 固定服務器角色的全部成員都有默認架構 dbo。架構
僅當新用戶名的 SID 與在數據庫中記錄的 SID 匹配時,才能更改映射到 Windows 登陸名或組的用戶的名稱。此檢查將幫助防止數據庫中的 Windows 登陸名欺騙。app
使用 WITH LOGIN 子句能夠將用戶從新映射到一個不一樣的登陸名。 不能使用此子句從新映射如下用戶:不具備登陸名的用戶、映射到證書的用戶或映射到非對稱密鑰的用戶。 只能從新映射 SQL 用戶和 Windows 用戶(或組)。 不能使用 WITH LOGIN 子句更改用戶類型,例如將 Windows 賬戶更改成 SQL Server 登陸名。函數
若是知足如下條件,則用戶的名稱會自動重命名爲登陸名。工具
用戶是一個 Windows 用戶。ui
名稱是一個 Windows 名稱(包含反斜槓)。加密
未指定新名稱。
當前名稱不一樣於登陸名。
若是不知足上述條件,則不會重命名用戶,除非調用方另外調用了 NAME 子句。
被映射到 SQL Server 登陸名、證書或非對稱密鑰的用戶名不能包含反斜槓字符 ()。
更改用戶名須要具備 ALTER ANY USER 權限。
更改用戶的目標登陸名須要對數據庫擁有 CONTROL 權限。
若要更改對數據庫擁有 CONTROL 權限的用戶名名稱,則須要對數據庫擁有 CONTROL 權限。
更改默認架構或語言須要對用戶擁有 ALTER 權限。 用戶可更改本身的默認架構或語言。
一、鏈接服務器-》在對象資源管理器窗口-》展開數據庫-》選擇數據庫並展開-》展開安全性-》展開用戶-》選擇要修改的用戶右鍵點擊-》選擇屬性。
二、在數據庫用戶彈出框-》點擊常規-》修改用戶默認架構。
三、在數據庫用戶彈出框-》點擊擁有的架構-》添加此用戶擁有的架構。
四、在數據庫用戶彈出框-》點擊成員身份-》添加或者刪除數據庫角色成員身份。
五、在數據庫用戶彈出框-》點擊安全對象-》點擊搜索添加安全對象-》點擊安全對象修改安全對象擁有的權限。
六、在數據庫用戶彈出框-》點擊擴展屬性-》添加或者刪除擴展屬性。
--建立用戶自定義數據庫用戶
--聲明數據庫引用
use database_name;
go
--修改用戶自定義數據庫用戶
alter user user_name
with
name=new_user_name,
default_schema={ schemaname | null },
login=login_name,
password='password' [old_password='old_password'],
default_language={ none | <lcid> | <language_name> | <language alias> },
allow_encrypted_value_modifications={ on | off }
--添加擁有的架構
use database_name;
go
alter authorization on schema::[db_accessadmin] to user_name;
go
alter authorization on schema::[db_backupoperator] to user_name;
go
alter authorization on schema::[db_datareader] to user_name;
go
alter authorization on schema::[db_datawriter] to user_name;
go
alter authorization on schema::[db_ddladmin] to user_name;
go
alter authorization on schema::[db_denydatareader] to user_name;
go
alter authorization on schema::[db_denydatawriter] to user_name;
go
alter authorization on schema::[db_owner] to user_name;
go
alter authorization on schema::[db_securityadmin] to user_name;
go
alter authorization on schema::[guest] to user_name;
go
刪除擁有的架構(把架構付給本身就好了)
go
alter authorization on schema::[db_accessadmin] to db_accessadmin;
go
alter authorization on schema::[db_backupoperator] to db_backupoperator;
go
alter authorization on schema::[db_datareader] to db_datareader;
go
alter authorization on schema::[db_datawriter] to db_datawriter;
go
alter authorization on schema::[db_ddladmin] to db_ddladmin;
go
alter authorization on schema::[db_denydatareader] to db_denydatareader;
go
alter authorization on schema::[db_denydatawriter] to db_denydatawriter;
go
alter authorization on schema::[db_owner] to db_owner;
go
alter authorization on schema::[db_securityadmin] to db_securityadmin;
go
alter authorization on schema::[guest] to guest;
go
--添加成員身份
use database_name;
go
alter role [db_accessadmin] add member user_name;
go
alter role [db_backupoperator] add member user_name;
go
alter role [db_datareader] add member user_name;
go
alter role [db_datawriter] add member user_name;
go
alter role [db_ddladmin] add member user_name;
go
alter role [db_denydatareader] add member user_name;
go
alter role [db_denydatawriter] add member user_name;
go
alter role [db_owner] add member user_name;
go
alter role [db_securityadmin] add member user_name;
go
--刪除成員身份
use database_name;
go
alter role [db_accessadmin] drop member user_name;
go
alter role [db_backupoperator] drop member user_name;
go
alter role [db_datareader] drop member user_name;
go
alter role [db_datawriter] drop member user_name;
go
alter role [db_ddladmin] drop member user_name;
go
alter role [db_denydatareader] drop member user_name;
go
alter role [db_denydatawriter] drop member user_name;
go
alter role [db_owner] drop member user_name;
go
alter role [db_securityadmin] drop member user_name;
go
--安全對象
--use database_name;
--go
--授予權限
--備份日誌
grant backup log to user_name;
go
--備份數據庫
grant backup database to user_name;
go
--插入
grant insert to user_name;
go
--查看定義
grant view definition to user_name;
go
--查看任意列加密密鑰定義
grant view any column encryption key definition to user_name;
go
--查看任意列主密鑰定義
grant view any column master key definition to user_name;
go
--查看數據庫狀態
grant view database state to user_name;
go
--撤銷掩碼
grant unmask to user_name;
go
--建立xml架構集合
grant create xml schema collection to user_name;
go
--建立表
grant create table to user_name;
go
--建立程序集
grant create assembly to user_name;
go
--建立隊列
GRANT CREATE QUEUE to user_name;
go
--建立對稱密鑰
grant create symmetric key to user_name;
go
--建立非對稱密鑰
grant create asymmetric key to user_name;
go
--建立服務
grant create service to user_name;
go
--建立規則
grant create rule to user_name;
go
--建立過程
grant create procedure to user_name;
go
--建立函數
grant create function to user_name;
go
--建立架構
grant create schema to user_name;
go
--建立角色
grant create role to user_name;
go
--建立類型
grant create type to user_name;
go
--建立路由
grant create route to user_name;
go
--建立默認值
grant create default to user_name;
go
--建立全文目錄
grant create fulltext catalog to user_name;
go
--建立視圖
grant create view to user_name;
go
--建立數據庫DDL事件通知
grant create database dll event notification to user_name;
go
--建立同義詞
grant create synonym to user_name;
go
--建立消息類型
grant create message type to user_name;
go
--建立遠程服務綁定
grant create remote service binding to user_name;
go
--建立約定
grant create contract to user_name;
go
--建立證書
grant create certificate to user_name;
go
--訂閱查詢通知
grant subscribe query notifications to user_name;
go
--更改
grant alter to user_name;
go
--更改任何外部數據源
grant alter any external data source to user_name;
go
--更改任何外部文件格式
grant alter any external file format to user_name;
go
--更改任何掩碼
grant alter any mask to user_name;
go
--更改任意安全策略
grant alter any security policy to user_name;
go
--更改任意程序集
grant alter any assembly to user_name;
go
--更改任意對稱密鑰
grant alter any symmetric key to user_name;
go
--更改任意非對稱密鑰
grant alter any asymmetric key to user_name;
go
--更改任意服務
grant alter any service to user_name;
go
--更改任意架構
grant alter any schema to user_name;
go
--更改任意角色
grant alter any role to user_name;
go
--更改任意路由
grant alter any route to user_name;
go
--更改任意全文目錄
grant alter any fulltext catalog to user_name;
go
--更改任意數據空間
grant alter any dataspace to user_name;
go
--更改任意數據庫DDL數據庫觸發器
grant alter any database ddl trigger to user_name;
go
--更改任意數據庫審覈
grant alter any database audit to user_name;
go
--更改任意數據庫事件通知
grant alter any database event notification to user_name;
go
--更改任意消息類型
grant alter any message type to user_name;
go
--更改任意應用程序角色
grant alter any application role to user_name;
go
--更改任意用戶
grant alter any user to user_name;
go
--更改任意遠程服務綁定
grant alter any remote service binding to user_name;
go
--更改任意約定
grant alter any contract to user_name;
go
--更改任意證書
grant alter any certificate to user_name;
go
--更新
grant update to user_name;
go
--檢查點
grant checkpoint to user_name;
go
--接管全部權
grant take ownership to user_name;
go
--控制
grant control to user_name;
go
--控制聚合
grant create aggregate to user_name;
go
--鏈接
grant connect to user_name;
go
--鏈接複製
grant connect replication to user_name;
go
--刪除
grant delete to user_name;
go
--身份驗證
grant authenticate to user_name;
go
--顯示計劃
grant showplan to user_name;
go
--選擇
grant select to user_name;
go
--引用
grant references to user_name;
go
--執行
grant execute to user_name;
go
--授予並容許轉售權限
--安全對象
--use database_name;
--go
--備份日誌
grant backup log to user_name with grant option;
go
--備份數據庫
grant backup database to user_name with grant option;
go
--插入
grant insert to user_name with grant option;
go
--查看定義
grant view definition to user_name with grant option;
go
--查看任意列加密密鑰定義
grant view any column encryption key definition to user_name with grant option;
go
--查看任意列主密鑰定義
grant view any column master key definition to user_name with grant option;
go
--查看數據庫狀態
grant view database state to user_name with grant option;
go
--撤銷掩碼
grant unmask to user_name with grant option;
go
--建立xml架構集合
grant create xml schema collection to user_name with grant option;
go
--建立表
grant create table to user_name with grant option;
go
--建立程序集
grant create assembly to user_name with grant option;
go
--建立隊列
GRANT CREATE QUEUE to user_name with grant option;
go
--建立對稱密鑰
grant create symmetric key to user_name with grant option;
go
--建立非對稱密鑰
grant create asymmetric key to user_name with grant option;
go
--建立服務
grant create service to user_name with grant option;
go
--建立規則
grant create rule to user_name with grant option;
go
--建立過程
grant create procedure to user_name with grant option;
go
--建立函數
grant create function to user_name with grant option;
go
--建立架構
grant create schema to user_name with grant option;
go
--建立角色
grant create role to user_name with grant option;
go
--建立類型
grant create type to user_name with grant option;
go
--建立路由
grant create route to user_name with grant option;
go
--建立默認值
grant create default to user_name with grant option;
go
--建立全文目錄
grant create fulltext catalog to user_name with grant option;
go
--建立視圖
grant create view to user_name with grant option;
go
--建立數據庫DDL事件通知
grant create database dll event notification to user_name with grant option;
go
--建立同義詞
grant create synonym to user_name with grant option;
go
--建立消息類型
grant create message type to user_name with grant option;
go
--建立遠程服務綁定
grant create remote service binding to user_name with grant option;
go
--建立約定
grant create contract to user_name with grant option;
go
--建立證書
grant create certificate to user_name with grant option;
go
--訂閱查詢通知
grant subscribe query notifications to user_name with grant option;
go
--更改
grant alter to user_name with grant option;
go
--更改任何外部數據源
grant alter any external data source to user_name with grant option;
go
--更改任何外部文件格式
grant alter any external file format to user_name with grant option;
go
--更改任何掩碼
grant alter any mask to user_name with grant option;
go
--更改任意安全策略
grant alter any security policy to user_name with grant option;
go
--更改任意程序集
grant alter any assembly to user_name with grant option;
go
--更改任意對稱密鑰
grant alter any symmetric key to user_name with grant option;
go
--更改任意非對稱密鑰
grant alter any asymmetric key to user_name with grant option;
go
--更改任意服務
grant alter any service to user_name;
go
--更改任意架構
grant alter any schema to user_name with grant option;
go
--更改任意角色
grant alter any role to user_name with grant option;
go
--更改任意路由
grant alter any route to user_name with grant option;
go
--更改任意全文目錄
grant alter any fulltext catalog to user_name with grant option;
go
--更改任意數據空間
grant alter any dataspace to user_name with grant option;
go
--更改任意數據庫DDL數據庫觸發器
grant alter any database ddl trigger to user_name with grant option;
go
--更改任意數據庫審覈
grant alter any database audit to user_name with grant option;
go
--更改任意數據庫事件通知
grant alter any database event notification to user_name with grant option;
go
--更改任意消息類型
grant alter any message type to user_name with grant option;
go
--更改任意應用程序角色
grant alter any application role to user_name with grant option;
go
--更改任意用戶
grant alter any user to user_name with grant option;
go
--更改任意遠程服務綁定
grant alter any remote service binding to user_name with grant option;
go
--更改任意約定
grant alter any contract to user_name with grant option;
go
--更改任意證書
grant alter any certificate to user_name with grant option;
go
--更新
grant update to user_name with grant option;
go
--檢查點
grant checkpoint to user_name with grant option;
go
--接管全部權
grant take ownership to user_name with grant option;
go
--控制
grant control to user_name with grant option;
go
--控制聚合
grant create aggregate to user_name with grant option;
go
--鏈接
grant connect to user_name with grant option;
go
--鏈接複製
grant connect replication to user_name with grant option;
go
--刪除
grant delete to user_name with grant option;
go
--身份驗證
grant authenticate to user_name with grant option;
go
--顯示計劃
grant showplan to user_name with grant option;
go
--選擇
grant select to user_name with grant option;
go
--引用
grant references to user_name with grant option;
go
--執行
grant execute to user_name with grant option;
go
--拒絕權限
--安全對象
use database_name;
go
--備份日誌
deny backup log to user_name;
go
--備份數據庫
deny backup database to user_name;
go
--插入
deny insert to user_name;
go
--查看定義
deny view definition to user_name;
go
--查看任意列加密密鑰定義
deny view any column encryption key definition to user_name;
go
--查看任意列主密鑰定義
deny view any column master key definition to user_name;
go
--查看數據庫狀態
deny view database state to user_name;
go
--撤銷掩碼
deny unmask to user_name;
go
--建立xml架構集合
deny create xml schema collection to user_name;
go
--建立表
deny create table to user_name;
go
--建立程序集
deny create assembly to user_name;
go
--建立隊列
deny CREATE QUEUE to user_name;
go
--建立對稱密鑰
deny create symmetric key to user_name;
go
--建立非對稱密鑰
deny create asymmetric key to user_name;
go
--建立服務
deny create service to user_name;
go
--建立規則
deny create rule to user_name;
go
--建立過程
deny create procedure to user_name;
go
--建立函數
deny create function to user_name;
go
--建立架構
deny create schema to user_name;
go
--建立角色
deny create role to user_name;
go
--建立類型
deny create type to user_name;
go
--建立路由
deny create route to user_name;
go
--建立默認值
deny create default to user_name;
go
--建立全文目錄
deny create fulltext catalog to user_name;
go
--建立視圖
deny create view to user_name;
go
--建立數據庫DDL事件通知
deny create database dll event notification to user_name;
go
--建立同義詞
deny create synonym to user_name;
go
--建立消息類型
deny create message type to user_name;
go
--建立遠程服務綁定
deny create remote service binding to user_name;
go
--建立約定
deny create contract to user_name;
go
--建立證書
deny create certificate to user_name;
go
--訂閱查詢通知
deny subscribe query notifications to user_name;
go
--更改
deny alter to user_name;
go
--更改任何外部數據源
deny alter any external data source to user_name;
go
--更改任何外部文件格式
deny alter any external file format to user_name;
go
--更改任何掩碼
deny alter any mask to user_name;
go
--更改任意安全策略
deny alter any security policy to user_name;
go
--更改任意程序集
deny alter any assembly to user_name;
go
--更改任意對稱密鑰
deny alter any symmetric key to user_name;
go
--更改任意非對稱密鑰
deny alter any asymmetric key to user_name;
go
--更改任意服務
deny alter any service to user_name;
go
--更改任意架構
deny alter any schema to user_name;
go
--更改任意角色
deny alter any role to user_name;
go
--更改任意路由
deny alter any route to user_name;
go
--更改任意全文目錄
deny alter any fulltext catalog to user_name;
go
--更改任意數據空間
deny alter any dataspace to user_name;
go
--更改任意數據庫DDL數據庫觸發器
deny alter any database ddl trigger to user_name;
go
--更改任意數據庫審覈
deny alter any database audit to user_name;
go
--更改任意數據庫事件通知
deny alter any database event notification to user_name;
go
--更改任意消息類型
deny alter any message type to user_name;
go
--更改任意應用程序角色
deny alter any application role to user_name;
go
--更改任意用戶
deny alter any user to user_name;
go
--更改任意遠程服務綁定
deny alter any remote service binding to user_name;
go
--更改任意約定
deny alter any contract to user_name;
go
--更改任意證書
deny alter any certificate to user_name;
go
--更新
deny update to user_name;
go
--檢查點
deny checkpoint to user_name;
go
--接管全部權
deny take ownership to user_name;
go
--控制
deny control to user_name;
go
--控制聚合
deny create aggregate to user_name;
go
--鏈接
deny connect to user_name;
go
--鏈接複製
deny connect replication to user_name;
go
--刪除
deny delete to user_name;
go
--身份驗證
deny authenticate to user_name;
go
--顯示計劃
deny showplan to user_name;
go
--選擇
deny select to user_name;
go
--引用
deny references to user_name;
go
--執行
deny execute to user_name;
go
--擴展屬性
--聲明數據庫引用
--use database_name
go
--添加擴展註釋
exec sys.sp_addextendedproperty @name=N'description_name', @value=N'description_value', @level0type=N'user',@level0name=N'user_name';
go
--刪除擴展註釋
exec sys.sp_dropextendedproperty @name=N'description_name', @level0type=N'user',@level0name=N'user_name'
go
複製代碼
--database_name
--數據庫名稱
--user_name
--指定在此數據庫中用於識別該用戶的名稱。
--login=login_name
--經過將用戶的安全標識符(SID)更改成另外一個登陸名的SID,使用戶從新映射到該登陸名。
--若是ALTER USER語句是SQL批處理中惟一的語句,則Windows Azure SQL Database將支持WITH LOGIN子句。
--若是 ALTER USER 語句不是SQL批處理中惟一的語句或在動態SQL中執行,則不支持WITH LOGIN子句。
--name=new_user_name
--指定此用戶的新名稱。 newUserName 不能已存在於當前數據庫中。
--default_schema={ schemaname | null }
--指定服務器在解析此用戶的對象名時將搜索的第一個架構。
--將默認架構設置爲NULL將從Windows組中刪除默認架構。Windows用戶不能使用NULL選項。
--password='password' [old_password='old_password']
--適用範圍:SQL Server 2012 (11.x)到SQL Server 201七、SQL Database。
--指定正在更改的用戶的密碼。 密碼是區分大小寫的。
--old_password='old_password'
--適用範圍:SQL Server 2012 (11.x)到SQL Server 201七、SQL Database。
--將替換爲「password」的當前用戶密碼。密碼是區分大小寫的。
--除非擁有ALTER ANY USER權限,不然須要具備OLD_PASSWORD才能更改密碼。須要OLD_PASSWORD可防止擁有IMPERSONATION權限的用戶更改密碼。
--此選項僅適用於包含的用戶。
--default_language={ none | | <language_name> | }
--適用範圍: SQL Server 2012 (11.x) 到 SQL Server 2017。
--指定將指派給用戶的默認語言。若是將此選項設置爲NONE,則默認語言將設置爲數據庫的當前默認語言。若是以後更改數據庫的默認語言,用戶的默認語言將保持不變。
--DEFAULT_LANGUAGE能夠爲本地 ID (lcid)、語言的名稱或語言別名。
--此選項只能在包含數據庫中指定,且只能用於包含的用戶。
--allow_encrypted_value_modifications={ on | off }
--適用範圍:SQL Server 2016 (13.x)到SQL Server 201七、SQL Database。
--取消在大容量複製操做期間對服務器進行加密元數據檢查。 這使用戶可以在表或數據庫之間大容量複製加密數據,而無需對數據進行解密。 默認爲 OFF。
--description_name
--用戶自定義用戶註釋名稱
--description_value
--用戶自定義用戶註釋值
/**********示例**********/
--聲明數據庫引用
use [testss];
go
--添加擁有的架構
alter authorization on schema::[db_accessadmin] to test1;
go
--刪除擁有的架構
alter authorization on schema::[db_accessadmin] to db_accessadmin;
go
--添加成員身份
alter role [db_backupoperator] add member test1;
go
alter role [db_datareader] add member test1;
go
--刪除成員身份
alter role [db_backupoperator] drop member test1;
go
alter role [db_datareader] drop member test1;
go
--安全對象
--授予權限
--備份日誌
grant backup log to test1;
go
--擴展屬性
--刪除擴展屬性
exec sys.sp_dropextendedproperty @name=N'tests_description', @level0type=N'user',@level0name=N'test1'
go
--添加擴展註釋
exec sys.sp_addextendedproperty @name=N'tests_description', @value=N'用戶自定義用戶描述', @level0type=N'user',@level0name=N'test1';
go
--修改當前數據庫用戶自定義用戶屬性
alter user test1
with
name=test1,
default_schema=dbo,
--login=tests,
--password='1234' old_password='1234',
--default_language=English,
allow_encrypted_value_modifications=off;
go
複製代碼