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
 Default Contraint *** RESOLVED***

Author  Topic 

JacobPressures
Posting Yak Master

112 Posts

Posted - 2005-08-16 : 10:43:32
You can't have but one default contraint in a DB named
df_revisiondate Default getdate()

I thought that sense they were being created on different Tables that it would not matter. It was a way to maintain a type of consistency by giving them the same name. However, it SEEMS to have caused all my tables to crash.

thanks!

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2005-08-16 : 12:32:36
All object names (table names, view names, procedure names, constraint names, etc.) must be unique across the system, when considering the full four-part naming (ServerName.DatabaseName.OwnerName.ObjectName). Since many people create all their objects as owned by dbo, that means that for them, within a database, each object has to have a unique name.

---------------------------
EmeraldCityDomains.com
Go to Top of Page

JacobPressures
Posting Yak Master

112 Posts

Posted - 2005-08-16 : 13:29:55
Thanks! I don't like that. I feel that if they do the same function they sould have the same name as long as it belongs to a different object.
Go to Top of Page

JacobPressures
Posting Yak Master

112 Posts

Posted - 2005-08-16 : 13:42:28
For example, you can have column names be the same as long as they are in different Tables. I named my Default contraint after the column it affects in that table. The default is applied to that column!

Now i have to come up with some type of naming convention just to remember all my default contraints when they all do the same thing!
Go to Top of Page

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2005-08-16 : 17:04:27
Well, fields are a part of a table object, but constraints are a distinct object.

So, you can either use a naming convention to make them unique like appending the table and field names to the default name, or maybe just using the name DFLT_TableName_ColumnName.

Or, another approach would be to use the CREATE DEFAULT command to create a stand-alone default object, and then use sp_bindefault to bind that default object to multiple tables and fields.

---------------------------
EmeraldCityDomains.com
Go to Top of Page

JacobPressures
Posting Yak Master

112 Posts

Posted - 2005-08-17 : 12:08:18
Great info! Thanks!

"Or, another approach would be to use the CREATE DEFAULT command to create a stand-alone default object, and then use sp_bindefault to bind that default object to multiple tables and fields."

I will look into this! Thanks again!

Go to Top of Page
   

- Advertisement -