Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Alter statement problem

Author  Topic 

susan_151615
Yak Posting Veteran

99 Posts

Posted - 2009-05-05 : 09:45:45
Hi i have a query in the form
"IF NOT EXISTS (
SELECT
1
FROM syscolumns
WHERE name = 'chip'
AND id=object_id('dbo.Log')
)
BEGIN
ALTER TABLE Log ADD chip BIT DEFAULT 0
END"


its adding the column but its not setting the value to default .how can i accomplish this in the same alter statement .Can anyone help me urgent.

similarly i have column with defualt as getdate ,identity(1,1) even that not working


susan

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-05-05 : 10:18:16
It is effecting when data are added newly
To update data which are already available, you need to update them


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-05-05 : 10:19:16
The syntax looks right to me. Is your problem that the existing rows are not showing the default value specified ? Specifying default won't affect the rows which are already in the table. It'll be defaulted with every insert after you alter the table.
Go to Top of Page

susan_151615
Yak Posting Veteran

99 Posts

Posted - 2009-05-05 : 10:28:56
Ok thank you sakets am able to get what u r trying to tell

susan
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2009-05-05 : 12:25:13
also try adding [ WITH VALUES ] to your alter statement.

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL or How to sell Used Cars
For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page
   

- Advertisement -