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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Composite Key Naming Convention

Author  Topic 

sqllearner
Aged Yak Warrior

639 Posts

Posted - 2006-07-06 : 13:59:18
I designed a database and now as we are in the stage of extracting the script out of Erwin and we have a template which enforces the primary key as
xpk_%Substitute(%EntityName,%substr(' ',2,1),_)_%PK()
In the above case if we have one primary key like
tbl_employee have emp_id only then it creates a primary key as
xpk_tbl_employee_emp_id where as if i have composite key like
emp_details_id,emp_id,emp_ssn for tbl_emp_details table then
it would show as
xpk_tbl_emp_details_emp_details_id________________emp_id_____________emp_ssn

Is there any better naming convention I can use for the composite keys
because this big under score kills me sometimes the keys even gets trimmed off.

X002548
Not Just a Number

15586 Posts

Posted - 2006-07-06 : 14:10:40
Personally....

TableName_PK Primary Key
TableName_IX1 Index
TableName_IX2 Index
TableName_Tr1 Trigger
TableName_C1 Constraint

ect







Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-07-06 : 14:20:41
Here is our naming convention:

Primary key: PK_TableName
Index: IDX_Column1_Column2_...
Foreign key: FK_ParentTableName_ChildTableName
I can provide more if needed.

I prefer that the constraints and indexes be descriptive so that I know more information about it when I get an error.



Tara Kizer
aka tduggan
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-07-06 : 14:25:12
Well, when your in DB2 and limited to 18 bytes, it's kind of a pain.

Also, even though DB2 allows 18 for indexes, the underlying VSAM datasets are limited to 8 bytes so you have to watch for dups

Hope I didn't scare anyone



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-07-06 : 14:27:48
What's DB2? Just kidding!



Tara Kizer
aka tduggan
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-07-07 : 01:25:05
http://vyaskn.tripod.com/object_naming.htm

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2006-07-07 : 04:18:51
Something like this:

PK_tableName
PK_tableName__col1_col2 (composite primary key)
IX_tableName__col1_col2_col3
UIX_tableName__col1_col2_col3
UC_tableName__col1_col2_col3
FK_tableName_REF_tableName__cola_colb__cola_colb (not always enforced, and a shorter version is used.. hm)

rockmoose
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-07-07 : 08:52:43
quote:
Originally posted by tkizer

What's DB2? Just kidding!



Tara Kizer
aka tduggan



It's the second database access names if you don't supply a name





Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-07-07 : 11:17:16
quote:
Originally posted by X002548

Well, when your in DB2 and limited to 18 bytes, it's kind of a pain.

Also, even though DB2 allows 18 for indexes, the underlying VSAM datasets are limited to 8 bytes so you have to watch for dups

Hope I didn't scare anyone



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Why do you work with pre-industrial software?





CODO ERGO SUM
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2006-07-07 : 11:45:00
quote:
Why do you work with pre-industrial software?

Because it will run on his abacus?

Help us help YOU!
Read this blog entry for more details: http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

*need more coffee*
SELECT * FROM Users WHERE CLUE > 0
(0 row(s) affected)
Go to Top of Page
   

- Advertisement -