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). 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.
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).
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." 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. Found instructions on how to do this here:
https://codingsight.com/moving-existing-table-from-primary-filegroup-to-different-filegroup/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.