Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 primary key & foreign key

Author  Topic 

paritosh
Starting Member

42 Posts

Posted - 2011-09-01 : 01:32:23
is this mandatory in sql server

primary key length and foreign key lenght is same
on both dependent colomns

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-01 : 01:46:38
primary key and foreign key columns should have similar types and lengths.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

alexylee
Starting Member

14 Posts

Posted - 2011-09-01 : 13:21:31
Basically primary key or foreign key is not mandatory in SQL Server. However, it is recommended to have at least primary key since it represents the row with the key. Foreign key can be used if the table is related to another table or you need to enforce data integrity between the tables.

Sometimes client API layer can require Primary key. For example, if you are using LINQ to SQL to access the SQL table, the table should have primary key.

Thanks,
Alex
[url]http://sqlbeyond.blogspot.com[/url]
[url]http://www.sqlmgmt.com[/url]
Go to Top of Page
   

- Advertisement -