如何在SQL Azure数据库中创建新用户? [英] How do I create a new user in a SQL Azure database?

查看:288
本文介绍了如何在SQL Azure数据库中创建新用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下模板:

I am trying to use the following template:

-- =================================================
-- Create User as DBO template for SQL Azure Database
-- =================================================
-- For login <login_name, sysname, login_name>, create a user in the database
CREATE USER <user_name, sysname, user_name>
    FOR LOGIN <login_name, sysname, login_name>
    WITH DEFAULT_SCHEMA = <default_schema, sysname, dbo>
GO

-- Add user to the database owner role
EXEC sp_addrolemember N'db_owner', N'<user_name, sysname, user_name>'
GO

我想创建一个名为user1的用户,其密码为'user1pass'.我连接了默认数据库身份验证",并打开了一个查询窗口.

I would like to create a user called user1 with a password of 'user1pass'. I connected with my default database 'authentication' and I have a query window open.

但是模板对我来说没有意义.例如,什么是sysname,在哪里提供密码以及应该将什么用作default_schema?

But the template does not make sense for me. For example what's sysname, where do I supply the password and what should I use as the default_schema?

特定用户需要有权执行所有操作.但是,如何设置它以便他可以执行所有操作?如果我将用户设为数据库所有者,那可以完成吗?

The particular user needs to have the power to do everything. But how do I set it up so he can do everything, is that done if I make the user a database owner?

到目前为止,我已经尝试过:

So far I have tried:

CREATE USER user1, sysname, user1
    FOR LOGIN user1, sysname, user1
    WITH DEFAULT_SCHEMA = dbo, sysname, dbo
GO

给予:

信息102,级别15,状态1,第1行在,"附近的语法不正确.

Msg 102, Level 15, State 1, Line 1 Incorrect syntax near ','.

和:

CREATE USER user1
    FOR LOGIN user1
    WITH DEFAULT_SCHEMA = dbo
GO

给予:

信息15007,第16级,状态1,第1行"user1" i

Msg 15007, Level 16, State 1, Line 1 'user1' i

不是有效的登录名,或者您没有权限.

s not a valid login or you do not have permission.

推荐答案

查看此链接以获取所有信息: https://azure.microsoft.com/zh-cn/blog/adding-users-to-your-sql-azure-database/

Check out this link for all of the information : https://azure.microsoft.com/en-us/blog/adding-users-to-your-sql-azure-database/

首先,您需要为SQL Azure创建一个登录名,其语法如下:

First you need to create a login for SQL Azure, its syntax is as follows:

CREATE LOGIN username WITH password='password';

此命令需要在主数据库中运行.之后,您才可以运行命令在数据库中创建用户. SQL Azure或SQL Server的工作方式是先在服务器级别创建一个登录名,然后将其映射到每个数据库中的用户.

This command needs to run in master db. Only afterwards can you run commands to create a user in the database. The way SQL Azure or SQL Server works is that there is a login created first at the server level and then it is mapped to a user in every database.

HTH

这篇关于如何在SQL Azure数据库中创建新用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆