July 8, 2013 at 8:54 am
hi
i want to add column with no check constraint
like
alter table emp with nocheck
add column1 not null
and then i need to update with default values and then i need to make table with check
how to do it
July 8, 2013 at 9:09 am
riya_dave (7/8/2013)
hii want to add column with no check constraint
like
alter table emp with nocheck
add column1 not null
and then i need to update with default values and then i need to make table with check
how to do it
The easiest way to do this is to add the column as a nullable column, update the new column and then alter it to NOT NULL.
alter table emp
add column1 varchar(10) null
go
update emp set column1 = 'hey'
go
alter table emp
alter column column1 varchar(10) not null
go
select * from emp
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
July 8, 2013 at 9:35 am
i need up date records in a batch,not just bulk insert
can anybody give me script for example i have 1256789 records and i need to update 5000 at a time
then next 5000,so it does not block anything
July 8, 2013 at 10:18 am
riya_dave (7/8/2013)
i need up date records in a batch,not just bulk insertcan anybody give me script for example i have 1256789 records and i need to update 5000 at a time
then next 5000,so it does not block anything
You really can't prevent locking but doing this in smaller batches will make the locks a lot shorter. This should minimize the impact on other processes. You can do this fairly easily in a loop.
while @@ROWCOUNT > 0
begin
update top (5000) emp set Column1 = 'hey'
from emp where Column1 is null
end
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
July 8, 2013 at 10:21 am
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply