unique values

  • im new in sql. how can i treat two columns of a table as a single primary key?

  • Is this what you want?

    CREATE TABLE [dbo].[Test] (

    [ColA] [int] NOT NULL ,

    [ColB] [varchar] (5) NOT NULL ,

    [ColC] [money] NOT NULL)

    GO

    ALTER TABLE [dbo].[Test] WITH NOCHECK ADD

    CONSTRAINT [PK_Test] PRIMARY KEY CLUSTERED ([ColA],[ColB])

    GO

  • Oops, should have added the following:

    Open Query Analyser.

    Change database to your database.

    Copy and paste code from previous post.

  • quote:


    Oops, should have added the following:

    Open Query Analyser.

    Change database to your database.

    Copy and paste code from previous post.


    tnx it helped me a lot. another question.

    what if i have two tables, table1 & table2.

    table1 contain columns -- table1id [uniqueID], name [varchar]

    table2 contain columns -- table1id [uniqueid], number [int]. table1id is a FK, number is not a unique value.

    what will be my PK for table2?

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

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