June 8, 2010 at 10:53 am
Is there a limit on the number of default values you can assign to your table? Or are you allowed to specify each column in your table with a default value? Thanks!
June 8, 2010 at 11:05 am
no limit the way you are thinking...you can have one default per column if you want...a table with 200 columns could potentially each have a default value for each of those columns.
Lowell
June 8, 2010 at 11:12 am
No, there is no limit 😀
declare @sqlstr NVARCHAR(MAX)
SET @sqlstr = N'CREATE TABLE defaultTester ('
DECLARE @i int = 0
WHILE @i < 1024
BEGIN
SET @sqlstr = @sqlstr + 'col' + cast(@i as varchar) + ' int default(' + cast(@i as varchar) + '),'
SET @i+=1;
print @i
END
set @sqlstr = substring(@sqlstr, 1, len(@sqlstr)-1)
set @sqlstr = @sqlstr +')'
print @sqlstr
EXEC sp_executesql @sqlstr
insert into defaultTester (col1) values (1)
select * from defaultTester
drop table defaultTester
-----------------------
SQL Server Database Copy Tool at Codeplex
June 8, 2010 at 11:24 am
Great, thank you both for your help!
And is this true for SQL Server 2000 and 2005 as well?
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply