No primary key created

  • Hi,

    The below script creates a table and my doubt is that it has a keyword PRIMARY but I makes no impact in creating this table (As I tries and verified the table structure NO PRIMARY KEY WAS CREATED). What is the actual intention creating a table using this script?

    [font="Verdana"]

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    SET ANSI_PADDING ON

    GO

    CREATE TABLE [dbo].[Temp](

    [Column1] [numeric](38, 0) NULL,

    [Column2] [varchar](90) NULL

    ) ON [PRIMARY]

    GO

    SET ANSI_PADDING OFF

    GO[/font]

    Thanks in advance.

    "I Love Walking In The Rain So No One Can See Me Crying ! " ~ Charlie Chaplin

  • haah!.....cos your above T-SQL code not create a primary key.

    the PRIMARY in the above code creates table on the primary filegroup.

    If you want to create a primary key:

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    SET ANSI_PADDING ON

    GO

    CREATE TABLE [dbo].[Temp](

    [ColumnID] [int] primary key,

    [Column1] [numeric](38, 0) NULL,

    [Column2] [varchar](90) NULL

    ) ON [PRIMARY]

    GO

    SET ANSI_PADDING OFF

    GO

  • jchandramouli (2/2/2009)


    What is the actual intention creating a table using this script?

    It creates a two column table on the primary filegroup. It won't create a primary key because there's no mention of a primary key in the script.

    Have a look at the CREATE TABLE section in Books Online. It should clarify things for you.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

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

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