来源:MS-SQL 2005
目标:MS-SQL 2012
不知怎的,我需要将开发数据库从一个更改为另一个,但遗憾的是“to database”确实已经有了一些表和SP,更糟糕的是,这些对象(如表)可能会有一些具有不同名称或类型的列甚至描述两者之间不一致。我应该做些什么来实现......也许更容易或更聪明,
到目前为止,我可以通过以下脚本找出一些统计数据
- 像SELECT * FROM INFORMATION_SCHEMA.COLUMNS一样,但每张桌子只选择一行
declare @temp_table_list table(
id int identity not null,
name varchar(100) not null
)
insert @temp_table_list(name) select name from sys.tables
declare @id int
declare @name varchar(100)
declare @result as nvarchar(max)
set @result = N''
while 1 = 1
begin
select @id = min(id)
FROM @temp_table_list
where id > isnull(@id,0)
if @id is null break
select @name = name
FROM @temp_table_list
where id = @id
declare @tbName as nvarchar(max)
declare @sql as nvarchar(max)
declare @col as nvarchar(max)
Set @tbName = @name
DECLARE T_cursor CURSOR FOR
select c.name from sys.columns c
inner join sys.tables t on c.object_id = t.object_id
inner join sys.types tp on tp.user_type_id = c.system_type_id
where t.name =@tbName
OPEN T_cursor
FETCH NEXT FROM T_cursor into @col
set @sql = N'select '
WHILE @@FETCH_STATUS = 0
BEGIN
set @sql = @sql+@col+','
FETCH NEXT FROM T_cursor into @col
END
set @sql =substring( @sql,0,len(@sql)) +' from '+ @tbName
CLOSE T_cursor
DEALLOCATE T_cursor
set @result = @result + @sql + '/r/n'
end
select @result
答案 0 :(得分:0)
这不是免费软件,但确实有试用期:
http://www.red-gate.com/products/sql-development/sql-compare/
听起来你的要求是一次性同步,那就应该做你想要的。