简体   繁体   English

将表和文件组从旧数据库复制到新数据库

[英]Copy Tables and FileGroups from old database to new database

Using SSMS in SQL Server 2017, I need to copy a set of tables from a legacy database into a new database on the same server (my localhost).在 SQL Server 2017 中使用 SSMS,我需要将一组表从旧数据库复制到同一服务器(我的本地主机)上的新数据库中。 The catch is that in the legacy database, when I script out the creation of some tables, they are created on a filegroup:问题是在遗留数据库中,当我编写一些表的创建脚本时,它们是在文件组上创建的:

CREATE TABLE [dbo].[Foobar](
    [FoobarId] [int] IDENTITY(1,1) NOT NULL,
    [OtherColumn] [varchar](100) NOT NULL) ON [AdvantagePrimary]

And when I run the script, of course, I get:当我运行脚本时,当然,我得到:

Invalid filegroup 'AdvantagePrimary' specified.指定的文件组“AdvantagePrimary”无效。

There are ~100+ tables and 14 filegroups I am scripting over to the new database (I need all the schema plus the table constraints, indexes, triggers, etc).有大约 100 多个表和 14 个文件组,我正在编写脚本到新数据库(我需要所有架构以及表约束、索引、触发器等)。

So my question is... Is it possible to copy over (with a script or otherwise) both the Tables and the FileGroups?所以我的问题是......是否可以复制(使用脚本或其他方式)表和文件组? The accepted answer here ( Is it possible to copy a filegroup from one database to another? ) seems to say "Nope. You are SOL."此处接受的答案( 是否可以将文件组从一个数据库复制到另一个数据库? )似乎说“不。你是 SOL。” I hope he's wrong.我希望他是错的。

I knew it was a long shot, but I tried this:我知道这是一个长镜头,但我试过这个:

INSERT INTO  NewDatabase.sys.filegroups
SELECT * FROM LegacyDatabase.sys.filegroups

And got:并得到:

Ad hoc updates to system catalogs are not allowed不允许对系统目录进行临时更新

Is there an easy way to do this?是否有捷径可寻?

I ended up just creating the filegroups manually in the target database.我最终只是在目标数据库中手动创建了文件组。 There were only 14 of them, so it wasn't too bad.他们只有14个,所以还不错。 Found instructions on how to do this here:在此处找到有关如何执行此操作的说明:

https://codingsight.com/moving-existing-table-from-primary-filegroup-to-different-filegroup/ https://codingsight.com/moving-existing-table-from-primary-filegroup-to-different-filegroup/

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM