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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Add a field in a table with 200.000 rows

Author  Topic 

footmaniac84
Starting Member

12 Posts

Posted - 2011-05-11 : 11:59:46
Hello,

I want to add a new field that doesn't allow NULL and have a default value of 0 in a table.

The problem is that this table is in use and have 200.000 rows.

When i try to add this field, an error occurs because of the timeout...

what can i do?

Thank you.

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-05-11 : 12:02:56
How are you adding the column? Using ALTER TABLE, or DROP and CREATE? If you're running this in Management Studio you shouldn't be getting a timeout error.
Go to Top of Page

footmaniac84
Starting Member

12 Posts

Posted - 2011-05-11 : 12:57:07
I am adding it with design view. I will try tomorrow to add it with a sql query.

i will tell you the result.

Thank you very much.
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-05-11 : 13:04:22
Yeah, read up on ALTER TABLE and do it that way. 200,000 rows is nothing unless you've got a very, very wide table on a very fragmented disk.
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2011-05-13 : 07:16:07

have a table dbo.Foo (Frst int, scnd char(3))

insert into Foo
select 1, 'sdr'
union all select 2, 'etw'

select * from Foo

alter table foo add bar int default 0 with values

select * from foo

drop table foo



http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

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

footmaniac84
Starting Member

12 Posts

Posted - 2011-05-19 : 05:41:40
Perfect.

Using alter table the time was less than two seconds....

Thank you!.
Go to Top of Page
   

- Advertisement -