Can PS be used to dump the SQL DDL to csv but do it in the order which would used to reload an empty database.. Tables
have lots of foreign key constraints . I would like to produce a file that I could use to rebuild an empty database, but foreign keys are causing me an issue.. I used a PS script that dumped SQL objects by type, but can it be scripted to have a "LOAD ORDER" of the tables.
Thanks.
June 17, 2021 at 7:54 pm
If you only need to do this occasionally, it might just be simpler to open the Object Explorer window in SSMS (press the {f8} key to open it if it's not already open) and then right-click on the database and select {Tasks}{Generate Scripts} and then follow your nose.
It's a real shame that MS doesn't have a stored procedure or other easily programmable method to do this. They did have an EXE file you could call a long time ago but they took that away a long time ago.
--Jeff Moden
Change is inevitable... Change for the better is not.
June 17, 2021 at 7:56 pm
p.s. I also wouldn't use the "data" feature of the above method because it creates and INSERT/VALUEs statement for every bloody row of data.
If you use a product like RedGate to do this for you, you'll have a similar issue with data.
--Jeff Moden
Change is inevitable... Change for the better is not.
June 17, 2021 at 8:15 pm
I have used that before.. but was looking for something that would dump tables in order with foreign key reference in mind, so I could pickup this file and create a new DB\tables without have to do backup-restore...
Thanks..
June 17, 2021 at 9:23 pm
Are you looking for a way to build a new database with no data - or do you need data also? If you want a database with the schema only - then take a look at DBCC CLONEDATABASE. Make sure to review the parameters available - as you would want to set the options for production and backup as that creates a production ready backup that can be restored to another instance.
If you need data pre-populated then you will need to identify that data and export to a file that can be used to import the data.
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
June 17, 2021 at 9:33 pm
I have used that before.. but was looking for something that would dump tables in order with foreign key reference in mind, so I could pickup this file and create a new DB\tables without have to do backup-restore...
Thanks..
Maybe I just got lucky in the past but I've not had the issue you speak of with it before. Knowing MS, it's probably the former. 😀
--Jeff Moden
Change is inevitable... Change for the better is not.
June 18, 2021 at 8:53 am
I have used that before.. but was looking for something that would dump tables in order with foreign key reference in mind, so I could pickup this file and create a new DB\tables without have to do backup-restore...
Thanks..
Have you considered using a DACPAC to do this?
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
June 18, 2021 at 11:54 am
What ever will work to be able to load a new copy of the DB with Foreign Key in mind during the process. I want basically a schema only
version of the DB, and thought PS would be able to sync the table loads based on Foreign Key constraints ..
Load tbl1 before tbl3 based on FK constraints type of logic
Thanks All replies so far...
DACPAC will do that. If you are not familiar, there is plenty of material available online. The process should be straightforward:
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
June 22, 2021 at 6:08 pm
Thanks that worked.
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply