如何在 SQL Azure 数据库中创建新用户?

How do I create a new user in a SQL Azure database?(如何在 SQL Azure 数据库中创建新用户?)
本文介绍了如何在 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/en-us/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';

此命令需要在 master db 中运行.只有在此之后,您才能运行命令在数据库中创建用户.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 数据库中创建新用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)
How can I generate an entity–relationship (ER) diagram of a database using Microsoft SQL Server Management Studio?(如何使用Microsoft SQL Server Management Studio生成数据库的实体关系(ER)图?)