none
CREATE TABLE Template

    Question

  • I accidentally altered the CREATE TABLE template from SQL Server Management Studio Express.  Now I don't have the original.  Could somebody please post CREATE TABLE template.
    Sunday, July 09, 2006 2:37 PM

Answers

  • -- =========================================

    -- Create table template

    -- =========================================

    USE <database, sysname, AdventureWorks>

    GO

    IF OBJECT_ID('<schema_name, sysname, dbo>.<table_name, sysname, sample_table>', 'U') IS NOT NULL

    DROP TABLE <schema_name, sysname, dbo>.<table_name, sysname, sample_table>

    GO

    CREATE TABLE <schema_name, sysname, dbo>.<table_name, sysname, sample_table>

    (

    <columns_in_primary_key, , c1> <column1_datatype, , int> <column1_nullability,, NOT NULL>,

    <column2_name, sysname, c2> <column2_datatype, , char(10)> <column2_nullability,, NULL>,

    <column3_name, sysname, c3> <column3_datatype, , datetime> <column3_nullability,, NULL>,

    CONSTRAINT <contraint_name, sysname, PK_sample_table> PRIMARY KEY (<columns_in_primary_key, , c1>)

    )

    GO

    Sunday, July 09, 2006 2:53 PM

All replies

  • -- =========================================

    -- Create table template

    -- =========================================

    USE <database, sysname, AdventureWorks>

    GO

    IF OBJECT_ID('<schema_name, sysname, dbo>.<table_name, sysname, sample_table>', 'U') IS NOT NULL

    DROP TABLE <schema_name, sysname, dbo>.<table_name, sysname, sample_table>

    GO

    CREATE TABLE <schema_name, sysname, dbo>.<table_name, sysname, sample_table>

    (

    <columns_in_primary_key, , c1> <column1_datatype, , int> <column1_nullability,, NOT NULL>,

    <column2_name, sysname, c2> <column2_datatype, , char(10)> <column2_nullability,, NULL>,

    <column3_name, sysname, c3> <column3_datatype, , datetime> <column3_nullability,, NULL>,

    CONSTRAINT <contraint_name, sysname, PK_sample_table> PRIMARY KEY (<columns_in_primary_key, , c1>)

    )

    GO

    Sunday, July 09, 2006 2:53 PM
  • Or the simplified version:

    Create Table MyTable(FirstField varchar(50), SecondField int)

    or...

    when in doubt >> Right Click in Management Studio to create a new table manually

    Adamus

    Sunday, July 09, 2006 10:54 PM
  • Thanks, joeydj,

    johncelmer

    Tuesday, July 11, 2006 3:20 AM