Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

how ro create a table with multiple coloumns defined to a single primary key Expand / Collapse
Author
Message
Posted Saturday, January 29, 2011 3:56 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, July 20, 2014 12:05 AM
Points: 4, Visits: 54
how ro create a table with multiple coloumns defined to a single primary key, please provide examples of any such table
Post #1055840
Posted Saturday, January 29, 2011 4:26 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:39 AM
Points: 6,826, Visits: 13,280
I'm sure this link will help you.



Lutz
A pessimist is an optimist with experience.

How to get fast answers to your question
How to post performance related questions
Links for Tally Table , Cross Tabs and Dynamic Cross Tabs , Delimited Split Function
Post #1055842
Posted Sunday, January 30, 2011 4:53 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, April 25, 2014 10:51 AM
Points: 2, Visits: 47
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".
Post #1055881
Posted Sunday, January 30, 2011 5:28 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, September 9, 2014 5:27 AM
Points: 369, Visits: 1,214
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
Post #1055883
Posted Sunday, January 30, 2011 11:48 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, July 20, 2014 12:05 AM
Points: 4, Visits: 54
@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.
Post #1055989
Posted Monday, January 31, 2011 1:27 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, September 9, 2014 5:27 AM
Points: 369, Visits: 1,214
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
Post #1056425
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse