更新时间:2023-02-08 17:21:09
查看包含的数据库用户模型( https://msdn.microsoft.com/en-us/library/ff929188.aspx ).
Look into the Contained Database User Model (https://msdn.microsoft.com/en-us/library/ff929188.aspx).
在包含的数据库用户模型中,不存在master数据库中的登录名.而是在用户数据库上进行身份验证过程,并且用户数据库中的数据库用户在主数据库中没有关联的登录名.
In the contained database user model, the login in the master database is not present. Instead, the authentication process occurs at the user database, and the database user in the user database does not have an associated login in the master database.
IF NOT EXISTS (
SELECT [name]
FROM sys.database_principals
WHERE [name] = 'myusername'
)
BEGIN
CREATE USER [myusername] WITH PASSWORD = '********';
END