User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 401,692 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,746 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Views: 8870 | Replies: 2
Reply
Join Date: Nov 2005
Posts: 2
Reputation: gymanual is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
gymanual gymanual is offline Offline
Newbie Poster

Default value of a column

  #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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2005
Location: Dubai,UAE
Posts: 36
Reputation: noman78 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
noman78's Avatar
noman78 noman78 is offline Offline
Light Poster

Re: Default value of a column

  #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  
Join Date: Jul 2005
Location: Dallas, TX
Posts: 481
Reputation: campkev is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: Default value of a column

  #3  
Nov 30th, 2005
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
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MS SQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MS SQL Forum

All times are GMT -4. The time now is 8:00 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC