--修改所有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
--ALTER TABLE table_name RENAME COLUMN column_name TO new_column_name;
select @SQL='alter table '+@TableName+' RENAME COLUMN '+@FielName+' TO '+ SUBSTRING(@FielName, 2, len(@FielName)-1)
print @SQL
--Exec(@SQL)
Fetch next from selectTableNmae into @TableName,@FielName
end
Close selectTableNmae
DeAllocate selectTableNmae