我在本地SQL Server 14.0.1000.169数据库上以sa身份登录,并尝试运行以下脚本:
CREATE USER [myuser] FOR LOGIN [myuser] WITH DEFAULT_SCHEMA=[dbo]
GO
我得到以下结果:
Msg 15007, Level 16, State 1, Line 1
myuser is not a valid login or you do not have permission
我仔细检查了一下,发现myuser
不存在,而dbo
确实存在,知道有什么问题吗?
答案 0 :(得分:0)
Before Creating a User you must first create a global Login.
under Security -> Logins -> NewLogin
Or
First connect to the server and switch to the master database. In master create a login and then add a user for that login to the master database.
CREATE LOGIN [MyLogin] WITH password='xxxxxxxxx'
GO
CREATE USER [MyUser] FOR LOGIN [MyLogin] WITH DEFAULT_SCHEMA=[dbo]
GO
Once the login exists you can add them as a User under a particular database.