Novice question about building databases from master script

  • I have a master script that contains all the object in an existing database all scripted out to be run and create those objects, but when I run it I receive all kinds of failure messages. Things like...

    //**** Failed To Add STIUser Schema ****//

    Cannot find the user 'STIUser', because it does not exist or you do not have permission

    Can anyone please advice me on the order in which I should be running scripts to create specific objects (i.e. tables, stored procedures, schemas, users, roles, etc...)?

    My thoughts are that they should be run in the order something like this:

    users

    schemas

    tables

    stored procedures

    etc...

    A clever person solves a problem. A wise person avoids it. ~ Einstein
    select cast (0x5365616E204465596F756E67 as varchar(128))

  • You definitely need logins and users early, perhaps roles as well. I think you have a good list there.

    Here are some things I learned awhile back. I didn't have users or schemas in there, but this should help with other objects: http://www.sqlservercentral.com/articles/System+Development+Life+Cycle/vcspart3/525/

    Note that my company, Red Gate Software, sells a couple tools that can help. They build a dependency tree and ensure that objects are created in the proper order. If might be worth the $$ to you to grab one copy, run it against your master db, save off the script for use by your app.

  • In addition to the order, you also have to worry about permissions. Do you have permissions to create the objects? Once created, do the objects have permissions to see other objects?

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Thanks for all the input!

    A clever person solves a problem. A wise person avoids it. ~ Einstein
    select cast (0x5365616E204465596F756E67 as varchar(128))

  • the format I follow is

    Database

    Logins

    Users schema

    Tables

    constraints

    Indexes

    Triggers

    data

    indexes

    functions

    procs

    everything else

    Jayanth Kurup[/url]

Viewing 5 posts - 1 through 4 (of 4 total)

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