Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create and Update new field SQL 2005 1

Status
Not open for further replies.

Rob7412

Technical User
Jan 26, 2006
31
US
I have a script that adds a bit field to an existing table, Default value of 0. I would like the same script to also go in and update the field to a bit value of 1 after creating it but the server keeps giving and error saying field does not exist. If i refresh the db the field is there but the script cannot see it. any idea on how to handle this? Thanks for any advice.

If Knowledge were power I would be a AAA Battery!
 
run this

Code:
create table a(id int)
go
insert a values(1)
go
select 'before addition of column',* from  a
go
alter table a add Col int default 0
go
select 'before update',* from  a
update a set col = 666
go
select 'after update',* from  a
go
drop table a
go

Denis The SQL Menace
--------------------
SQL Server Code,Tips and Tricks, Performance Tuning
SQLBlog.com, Google Interview Questions
 
Fantastic Thanks

If Knowledge were power I would be a AAA Battery!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top