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

3
Contributors
2
Replies
3
Views
11 Years
Discussion Span
Last Post by campkev
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

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
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.