Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Azure by (45.3k points)

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

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.

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

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

and:

CREATE USER user1

    FOR LOGIN user1

    WITH DEFAULT_SCHEMA = dbo

GO

and:

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

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

1 Answer

0 votes
by (16.8k points)

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

 CREATE LOGIN username WITH password='password';

Run this command in Master DB only.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...