how ro create a table with multiple coloumns defined to a single primary key

  • how ro create a table with multiple coloumns defined to a single primary key, please provide examples of any such table

  • I'm sure this link will help you.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • It is very important for you to know how to read tsql documentation. Even better, download it and install locally. Effort on that will give you many benefits and faster advancement in knowledge.

    Here is example of multicolumn primary key, along with two foreign keys:

    CREATE TABLE MyTable

    (

    ForeignId1 int,

    ForeignId2 int,

    CONSTRAINT MyTable_PK

    PRIMARY KEY ( ForeignID1, ForeignID2 ),

    CONSTRAINT MyTable_FK_Table1

    FOREIGN KEY ( ForeignID1 ) REFERENCES Table1( ID ),

    CONSTRAINT MyTable_FK_Table2

    FOREIGN KEY ( ForeignID2 ) REFERENCES Table2( ID )

    )

    Primary key = not null constraint + unique index

    Is is recommended to give table a PK that is artificial, e.g. "int identity".

  • Try a free tool XDetails (www.sqlxdetails.com). It really simple presents multicolumn PK, FK, column comments and other features.

    _____________________________________________________
    Microsoft Certified Master: SQL Server 2008
    XDetails Addin - for SQL Developers
    blog.sqlxdetails.com - Transaction log myths
  • @bright_day

    can you please provide me any link where i can learn tsql documentation as suggested by you, i am learning t-Sql development, kindly need assistance of experienced.

  • First, download the documentation. It is called "books online". Search with google books online for your version of sql server. This is example for SQL 2008R2 (put that in google):

    sql 2008R2 books online download

    First result is at Microsoft site. Download and install.

    When you are in query editor of SQL Server Management Studio, you can press F1 when text cursor is the keyword or function you want the details on. CONVERT function is the one that I use F1 the most, so I have marked that page as "Favorite" to be easily accessible.

    How to read T-SQL command syntax specification:

    http://msdn.microsoft.com/en-us/library/ms177563.aspx

    In short:

    [abc] = means that "abc" (anything within brackets) is optional, you can omit it

    {a | b | c } = means that contents of curly brackets is NOT optional. You HAVE TO select exactly one of the values that are separated by "|". E.g: a or b or c.

    [{a | b}] = that means you have to select a or b or nothing. It is the same as [ a | b ]

    {a | b}[,...n] = "[,...n]" means you can repeat that thing before as many as you like, as long as you separate them with comma. E.g: a,b,a,a,b,b,b,b

    <something> = contents of "something" is described somewhere else, usually in the same page just below.

    Try to explain this:

    CREATE TABLE

    [ database_name.[ owner ] . | owner. ] table_name

    ( { < column_definition >

    | column_name AS computed_column_expression

    | < table_constraint > } [ ,...n ]

    )

    Try to find function reference and read about all the functions that are built-in in sql server and try to use each in example. That's a good start.

    Good luck!

    _____________________________________________________
    Microsoft Certified Master: SQL Server 2008
    XDetails Addin - for SQL Developers
    blog.sqlxdetails.com - Transaction log myths

Viewing 6 posts - 1 through 5 (of 5 total)

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