--修改所有Detail Table 字段为Not in 'D' Name
declare @TableName varchar(50),@FielName varchar(50),@TableID varchar(20),@FieldID varchar(20),
@Table_Description varchar(200),@Field_Description varchar(200),
@SQL varchar(1000)
Declare selectTableNmae cursor for
SELECT o.name, c.name fieldname
FROM syscolumns c
INNER JOIN sysobjects o ON c.id = o.id
WHERE o.type = 'U' and LEFT(o.Name,2)='T_'
and RIGHT(o.Name,6)='Detail'
and SUBSTRING(o.Name, 3, len(o.Name)-8)=SUBSTRING(c.name, 2, len(c.name)-3)
and left(c.name,1)='D' and RIGHT(c.name,2)='ID'
ORDER BY o.name desc, c.name
Open selectTableNmae
select @TableName='',@FielName=''
Fetch next from selectTableNmae into @TableName,@FielName
While @@Fetch_Status = 0
begin
--print @TableName
--print @FielName
--EXEC sp_rename '表名.旧字段名', '新字段名', 'COLUMN'
select @SQL='EXEC sp_rename '''+@TableName+'.'+@FielName+''','''+ SUBSTRING(@FielName, 2, len(@FielName)-1)+''',''COLUMN'''
--print @SQL
Exec(@SQL)
Fetch next from selectTableNmae into @TableName,@FielName
end
Close selectTableNmae
DeAllocate selectTableNmae