Primary Key on multiple columns

  • I'm sure it is on this site, but I have searched, skimmed, read and can't find it.

    I need the syntax to create a table and within the create table statement to include a primary key on 3 columns. BOL seems to only show single column primary keys.

    I'm attempting to use C.L.Graham's Column names, data types, and lengthshttp://www.sqlservercentral.com/scripts/contributions/784.aspto get an inventory of all fields from all tables from all databases on all of my servers. I would like to make sure I don't pull the information twice on a table so I want the primary key to be on dbname+table_name+column_name

    create table admin.dbo.Master_Table_Column_List

    (DBNAME char(25) not NULL,

    TABLE_NAME VARCHAR(50) NOT NULL,

    COL_NBR INT NOT NULL,

    COLUMN_NAME VARCHAR(25),

    DATATYPE VARCHAR(25)

    )

    Once I get this table created, then I want to use the msforeach ? command to work through all the databases.

    I would appreciate feedback if there is an easier/better way to do what I am attempting.

    Thank you for your help,

    Michelle



    Michelle

  • quote:


    I need the syntax to create a table and within the create table statement to include a primary key on 3 columns.


    Is this what you want?

    CREATE TABLE [dbo].[Trace2] (

    [RowNumber] [int] IDENTITY (1, 1) NOT NULL ,

    [EventClass] [int] NOT NULL ,

    [TextData] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,

    [BinaryData] [image] NULL ,

    [SPID] [int] NULL ,

    [Duration] [bigint] NULL,

    CONSTRAINT [PK__Trace2] PRIMARY KEY

    (

    [RowNumber],

    [EventClass])

    ) ON [PRIMARY]

    GO

  • That is it!

    Thanks,

    Michelle



    Michelle

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

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