Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 26th, 2005, 08:50 AM
Friend of Wrox
Join Date: Mar 2005
Posts: 264
Thanks: 0
Thanked 0 Times in 0 Posts
Default When to define primary keys and foregin keys?

Hi all. At what stage should we define the primary key and forgign key? After creating tables ? What is best practice? I be happy if explain these in the sql server 2000 environment.Thanks

Old August 26th, 2005, 09:14 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post

You should know what the primary key and foreign key constraints are before you even start typing at your keyboard. You *do* design your databases before you start defining them in EM, right? ;)

Now, there are legitimate debates as to whether you should create surrogate keys for other key values (e.g. identity columns). Sometimes, the use of a surrogate key isn't immediately apparent, so they may not be defined until later, but that aside, you should have a pretty good idea what your key values are in the tables which model your business entitites, and the relationships between those tables, before you even start typing their definitions in.

Therefore, since you know them already, you can define these keys and constraints as you are defining the tables, well before any data is loaded into them.


Jeff Mason
Custom Apps, Inc.

Similar Threads
Thread Thread Starter Forum Replies Last Post
inserting records with foreign and primary keys tdaustin Classic ASP Basics 0 October 4th, 2005 12:49 AM
Find() With multiple primary keys busher ASP.NET 1.0 and 1.1 Professional 0 June 2nd, 2005 03:00 PM
ASP and auto-generated primary keys Steve777 Classic ASP Professional 2 May 26th, 2005 10:47 AM
Thoughts on Primary keys rohan_man Access 3 February 9th, 2005 06:18 PM
Subform/Links ~ Too Many Primary Keys fdsi19 Access 1 September 30th, 2003 12:48 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.