943,968 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Unsolved
  • Views: 25634
  • MS SQL RSS
Nov 30th, 2005
0

Default value of a column

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gymanual is offline Offline
2 posts
since Nov 2005
Nov 30th, 2005
0

Re: Default value of a column

Quote 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
Reputation Points: 10
Solved Threads: 0
Light Poster
noman78 is offline Offline
40 posts
since Nov 2005
Nov 30th, 2005
0

Re: Default value of a column

I would go with the simpler computed column
MS SQL Syntax (Toggle Plain Text)
  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
Reputation Points: 14
Solved Threads: 19
Posting Pro in Training
campkev is offline Offline
484 posts
since Jul 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: new in sql world
Next Thread in MS SQL Forum Timeline: help with joins





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC