Home Forums SQL Server 2005 T-SQL (SS2K5) IF table exists, DROP TABLE then CREATE TABLE - script not working RE: IF table exists, DROP TABLE then CREATE TABLE - script not working

  • It is quite simple. Don't do this in the same batch.

    IF OBJECT_ID(N'dbo.mtzcus_2014_CoreMenuReportCriteria', N'U') IS NOT NULL

    DROP TABLE dbo.mtzcus_2014_CoreMenuReportCriteria;

    CREATE TABLE dbo.mtzcus_2014_CoreMenuReportCriteria

    (

    MeasureType VARCHAR(20) NOT NULL

    ,MeasureOrder TINYINT NOT NULL

    ,ObjectiveNumber VARCHAR(3) NOT NULL

    ,ObjectiveName VARCHAR(100)

    ,CriteriaCertificationNumber VARCHAR(50)

    ,ExclusionDescription VARCHAR(100)

    ,Threshold2014Stage2 DECIMAL(3, 0)

    ,Threshold2014Stage1 DECIMAL(3, 0)

    ,CONSTRAINT mtzcus_2014_CoreMenuReportCriteria_PK PRIMARY KEY CLUSTERED

    ( MeasureType, MeasureOrder, ObjectiveNumber )

    );

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/