Create user - TSQL

  • 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

  •  

    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

     

     

  • Thanks very very mutch Keith.

    I shall try soon

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply