sql server创建用户名
sql server创建用户名,过程如下
1)判断用户名'tt'是否存在
2)若不存在则创建'tt',并给予访问库'dd'的权限
------解决方案--------------------USE master
GO
IF (SELECT 1 FROM master.dbo.syslogins WHERE loginname='test') IS NOT NULL
DROP LOGIN [test]
GO
USE master
GO
CREATE LOGIN [test] WITH PASSWORD='12123asfdas!@#3'
go
USE [AdventureWorks]
GO
CREATE USER [test] FOR LOGIN [test]
GO
USE [AdventureWorks]
GO
EXEC sp_addrolemember N'db_owner', N'test'
GO
------解决方案--------------------IF EXISTS (SELECT * FROM sys.server_principals WHERE name = N'用户名')
DROP LOGIN [用户名]
GO
CREATE LOGIN [用户名] WITH PASSWORD=N'密码', DEFAULT_DATABASE=[默认数据库], DEFAULT_LANGUAGE=[简体中文], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO
EXEC sys.sp_addsrvrolemember @loginame = N'用户名', @rolename = N'sysadmin'
GO