Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Create user - TSQL Expand / Collapse
Author
Message
Posted Saturday, June 24, 2006 5:24 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Saturday, September 8, 2007 1:30 AM
Points: 4, Visits: 1
Hi all

(newbye)

I want write a script that can:
1° create a database (create database xxxx ..)
2° '??? add user ???' and grant him all privileges

How can do for 2° something as 'create user uid password' ?

thanks
castore
Post #289952
Posted Saturday, June 24, 2006 11:07 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, January 13, 2014 11:39 AM
Points: 89, Visits: 19

 

I don't know that this is what you are looking for but the following will create a database, its schema, a table and add a user such that the user can login into the server and into the default database with permissions granted on the schema.

Create Database GetStarted

On Primary

(NAME = 'GetStartedDB_dat',

Filename ='C:\Documents and Settings\admin\My Documents\SQL Server Management Studio\Projects\getstarteddb.mdf',

SIZE = 5MB,

MaxSize=25MB,

FILEGrowth= 10%)

LOG ON

(NAME='GetStartedDB_log',

FILENAME = 'C:\Documents and Settings\admin\My Documents\SQL Server Management Studio\Projects\getstarteddb.ldf',

SIZE = 5MB,

MaxSize=25MB,

FILEGrowth= 10%)

GO

Create Schema newdbs

Create Table EmployeeSummary

(EmpID int Identity(1,1) Primary Key,

EmployeeFirstName varchar(50),

EmployeeLastName varchar(50),

EmployeeBirthDate smalldatetime,

EmployeeNumberofChildren int,

EmployeeBankBalance Money)

GO

CREATE LOGIN LetMeStart

WITH PASSWORD = 'weneedtologinnow'

USE Getstarted

CREATE USER Geton FOR LOGIN Letmestart

WITH DEFAULT_SCHEMA = newdbs

go

GRANT Select, INSert, Update On Schema::newdbs TO Geton

GO

 

 




Post #289959
Posted Sunday, June 25, 2006 12:06 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Saturday, September 8, 2007 1:30 AM
Points: 4, Visits: 1
Thanks very very mutch Keith.
I shall try soon


Post #289960
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse