January 29, 2011 at 3:56 pm
how ro create a table with multiple coloumns defined to a single primary key, please provide examples of any such table
January 29, 2011 at 4:26 pm
I'm sure this link will help you.
January 30, 2011 at 4:53 am
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".
January 30, 2011 at 5:28 am
Try a free tool XDetails (www.sqlxdetails.com). It really simple presents multicolumn PK, FK, column comments and other features.
January 30, 2011 at 11:48 pm
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.
January 31, 2011 at 1:27 pm
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!
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply