CREATE DATABASE dynamically

  • It looks like the code for creating a database is fairly straight forward.  I am new to SQL though and am not sure where in Enterprise Manager to import the code.  Can some one point me in the right direction?  I want to import something like this:

    CREATE DATABASE profile

    CREATE TABLE profile_storage

    (

    ID int(4)

    NAME varchar

    ADDRESS varchar

    CITY varchar

    STATE varchar

    ZIP varchar

    PHONE varchar

    EMAIL varchar

    WEBSITE varchar

    PASSWORD varchar

    )

    Also, how do I set ID as the primary key?

    Thanks for taking the time to read this!

  • Hello John,

    You can script out each object in the database as follows from Enterprise Manager: Go to the specific SQL Server

    1. Right mouse click on any existing database and select the option "All Tasks -> Generate SQL Script"

    2. Click on "Show All" button on the top right side. Here select the required options.

    3. On the "Options" tab you can select the required options.

    Hope this helps you.

    Thanks

     


    Lucky

  • John,

    The place to run T-SQL code is in Query Analyzer, which can be started from Enterprise Manager or from the SQL Server Program group.

    You can set ID as the primary key like this:

    CREATE TABLE profile_storage

    (

    ID int(4) primary key,

    NAME varchar,

    ADDRESS varchar,

    CITY varchar,

    STATE varchar,

    ZIP varchar,

    PHONE varchar,

    EMAIL varchar,

    WEBSITE varchar,

    PASSWORD varchar

    )

    Note the required commas between columns.

    Greg

    Greg

  • Thank you Greg and Old Hand!! I'm on it

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

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