SQLTeam.com | Weblogs | Forums

Create Database


#1

Write a script that will create a database. Include the creation of a user named user1 with a password of pword1. Save the script as create_database.sql.


#2

We will help with homework, but you have to show effort. Posting just the problem is not showing any effort.


#3

so i just do:

CREATE Database Data_1;

CREATE LOGIN user1
WITH PASSWORD = 'pword1';
GO

-- Creates a database user for the login created above.
CREATE USER user1 FOR LOGIN user1;
GO


#4

That is pretty close. The thing that you need to do is to add the following before you create the user

USE Data_1
GO

That is because the user is a database level entity, and you want to create the user in the new database you created. IN order to do that, you have to make that database the current database.


#5

Ok thank you!!