Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Create user - TSQL


Create user - TSQL

Author
Message
castore
castore
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
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
Keith Risman
Keith Risman
SSC Journeyman
SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)

Group: General Forum Members
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





castore
castore
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 1
Thanks very very mutch Keith.
I shall try soon
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search