954,560 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Default value of a column

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

gymanual
Newbie Poster
2 posts since Nov 2005
Reputation Points: 10
Solved Threads: 0
 

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

noman78
Light Poster
40 posts since Nov 2005
Reputation Points: 10
Solved Threads: 0
 

I would go with the simpler computed column

CREATE TABLE [TableName] (
	[Column1Name] [int] IDENTITY (1, 1) NOT NULL ,
	[Column2Name] [int] NULL ,
	[Column3Name] AS ([Column1Name] + [Column2Name]) 
) ON [PRIMARY]
GO
campkev
Posting Pro in Training
484 posts since Jul 2005
Reputation Points: 14
Solved Threads: 19
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You