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.
| Author |
Topic |
|
ms65g
Constraint Violating Yak Guru
497 Posts |
Posted - 2009-12-17 : 10:45:21
|
| Hi,I am looking for a stored procedure like sp_msforeachtable that by using it set all null values to default,I mean all columns in all tables in a database. |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-12-17 : 11:46:57
|
| Execute this Query and run the result setselect 'Alter table '+o.name +' add constraint DF_cont_'+o.name+'_'+c.name +' Default null for '+c.name from sys.objects o inner join sys.columns c on c.object_id=o.object_id where o.type='u'Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
ms65g
Constraint Violating Yak Guru
497 Posts |
Posted - 2009-12-17 : 12:12:48
|
| Thanks, your idea is great but I was looking for this:select 'update '+o.name +' set ' +c.name +'= default '+' where '+c.name+ ' is null'from sys.objects o inner join sys.columns c on c.object_id=o.object_idwhere o.type='u' |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-12-18 : 01:23:46
|
quote: Originally posted by ms65g Thanks, your idea is great but I was looking for this:select 'update '+o.name +' set ' +c.name +'= default '+' where '+c.name+ ' is null'from sys.objects o inner join sys.columns c on c.object_id=o.object_idwhere o.type='u'
Then you need thisselect 'update '+table_name +' set ' +column_name +'= '+column_default+' where '+column_name+ ' is null ' from information_schema.columnswhere column_default is not nulland objectproperty(object_id(table_name),'istable')=1MadhivananFailing to plan is Planning to fail |
 |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-12-18 : 02:30:13
|
quote: Originally posted by ms65g Thanks, your idea is great but I was looking for this:select 'update '+o.name +' set ' +c.name +'= default '+' where '+c.name+ ' is null'from sys.objects o inner join sys.columns c on c.object_id=o.object_idwhere o.type='u'
Welcome Have you execute madhi's Query??Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
|
|
|