--创建登陆帐户(create login)
create login sp_read with password='sp_password', default_database=master
--为登陆账户创建数据库用户(create user),在mydb数据库中的security中的user下可以找到新创建sp_read
create user sp_read for login sp_read with default_schema=dbo
--通过加入数据库角色,赋予数据库用户“db_datareader”权限
exec sp_addrolemember 'db_datareader', 'sp_read'
--让 SQL Server 登陆帐户“sp_read”访问多个数据库
use mydb
go
create user sp_read for login sp_read with default_schema=dbo
go
exec sp_addrolemember 'db_datareader', 'sp_read'
go
use mydb2
go
create user sp_read for login sp_read with default_schema=dbo
go
exec sp_addrolemember 'db_datareader', 'sp_read'
go
create login sp_read with password='sp_password', default_database=master
--为登陆账户创建数据库用户(create user),在mydb数据库中的security中的user下可以找到新创建sp_read
create user sp_read for login sp_read with default_schema=dbo
--通过加入数据库角色,赋予数据库用户“db_datareader”权限
exec sp_addrolemember 'db_datareader', 'sp_read'
--让 SQL Server 登陆帐户“sp_read”访问多个数据库
use mydb
go
create user sp_read for login sp_read with default_schema=dbo
go
exec sp_addrolemember 'db_datareader', 'sp_read'
go
use mydb2
go
create user sp_read for login sp_read with default_schema=dbo
go
exec sp_addrolemember 'db_datareader', 'sp_read'
go