Default value of a column

Reply

Join Date: Nov 2005
Posts: 2
Reputation: gymanual is an unknown quantity at this point 
Solved Threads: 0
gymanual gymanual is offline Offline
Newbie Poster

Default value of a column

 
0
  #1
Nov 30th, 2005
PLs could somebody tell me how in MS SQL set the default value of a column as the sum of 2 columns

column3=column1+column2
where column3 is bigint
column1 and column2 are int
column1 is primary key with identity incresed by 1

if posibble column2 is a column from another table but the same db
Thanks a lot
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 40
Reputation: noman78 is an unknown quantity at this point 
Solved Threads: 0
noman78's Avatar
noman78 noman78 is offline Offline
Light Poster

Re: Default value of a column

 
0
  #2
Nov 30th, 2005
Originally Posted by gymanual
PLs could somebody tell me how in MS SQL set the default value of a column as the sum of 2 columns

column3=column1+column2
where column3 is bigint
column1 and column2 are int
column1 is primary key with identity incresed by 1

if posibble column2 is a column from another table but the same db
Thanks a lot
you can write a trigger on a table for insert update
and dotn pass the value for field, so whever u will enter the row or alter it, the next field which is formula will be generated automatically,
if u r unknown for triggers then inform me
i will tell u ow to make triggers
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 483
Reputation: campkev is an unknown quantity at this point 
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: Default value of a column

 
0
  #3
Nov 30th, 2005
I would go with the simpler computed column
  1. CREATE TABLE [TableName] (
  2. [Column1Name] [int] IDENTITY (1, 1) NOT NULL ,
  3. [Column2Name] [int] NULL ,
  4. [Column3Name] AS ([Column1Name] + [Column2Name])
  5. ) ON [PRIMARY]
  6. GO
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the MS SQL Forum


Views: 16525 | Replies: 2
Thread Tools Search this Thread



Tag cloud for MS SQL
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC