SQL SERVER2000,2005都能运行,2008不能正常运行的语句。 该语句的作用是查出约束的字段并生成添加的语句,在SQL SERVER2000,2005都能运行,但在SQL Server 2008下运行,AddDefaultConstraint字段出不来数据,检查后发现c.name的影响,因c.name出不来数据,因此请教大虾们是什么原因?
语句如下:
select 'ALTER TABLE [' + b.name + '] ADD CONSTRAINT [' + a.name + '] DEFAULT ' + d.text + ' FOR [' + c.name + ']' as [AddDefaultConstraint] ,'ALTER TABLE [' + b.name + '] DROP CONSTRAINT [' + a.name + ']' as [DropDefaultConstraint] from sysobjects a left join sysobjects b on a.parent_obj = b.id left join syscolumns c on a.parent_obj = c.id and a.info = c.colid left join syscomments d on a.id = d.id where a.xtype = 'd' order by b.name
------解决方案--------------------
SQL code
select @@VERSION
/*Microsoft SQL Server 2008 R2 (RTM) - 10.50.1617.0 (Intel X86)
Apr 22 2011 11:57:00
Copyright (c) Microsoft Corporation
Enterprise Evaluation Edition on Windows NT 6.1 <X64> (Build 7600: ) (WOW64)
(1 行受影响)
*/
------解决方案--------------------
a.info和c.colid两个字段分别是什么意思,你知道?
------解决方案--------------------