|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Set default value from another table?I have a field in a table which I need to set a default value for. The
default value needs to be a string concatenation of two fields from a DIFFERENT table. Anyone know how to do this? Thanks! SQL Server 2000. Do you really need to store this? Why can't you generate that from a VIEW
or directly in the SELECT statement? Show quote "MartyNg" <Mart***@gmail.com> wrote in message news:1121354940.832668.123400@g47g2000cwa.googlegroups.com... >I have a field in a table which I need to set a default value for. The > default value needs to be a string concatenation of two fields from a > DIFFERENT table. Anyone know how to do this? Thanks! > > SQL Server 2000. > The table that the default needs to go into is a major table and feeds
into several other systems. Is there not an easy way to grab this data? Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, data types, etc. in your schema are. Sample data is also a good idea, along with clear specifications. It is very hard to debug code when you do not let us see it. If the default may change (I assume that's why it's in a table) but you
need to preserve the historical values then do the join as part of the INSERT. If the default doesn't change or you don't need to preserve history then the column is redundant - drop it and use a view. The fact that it feeds several other systems shouldn't stop you doing that. -- David Portas SQL Server MVP -- >> have a field [sic] in a table which I need to set a default value for. The default value needs to be a string concatenation of two fields [sic] from a DIFFERENT table. << No. The idea is absurd. That would allow the DEFAULT value to bechanged during execution. That would destroy insertions, updates and DRI actions. You do not seem to understand what a DEFAULT does. Rows are not records and fields are columns. If you need to reference a second table, then use a VIEW. > Rows are not records and fields are columns. Joe! You just said fields are columns! :-)Typo! Typo! Typo! The dog bit my fingers. Really. I have bandages
on both hands from breaking up a dog fight manually last week. Let's put the new rule up there with "Do not fry bacon without a shirt." I bet I know why they were fighting. One dog said to the other dog "let's go
running in that column". They other dog replied "columns are not fields...." Show quote "--CELKO--" wrote: > Typo! Typo! Typo! The dog bit my fingers. Really. I have bandages > on both hands from breaking up a dog fight manually last week. Let's > put the new rule up there with "Do not fry bacon without a shirt." > > |
|||||||||||||||||||||||