https://github.com/borispinsky/Clone-database-with-schema-only-
Clone database with schema only using SqlPackage.exe utility
https://github.com/borispinsky/Clone-database-with-schema-only-
Last synced: 4 months ago
JSON representation
Clone database with schema only using SqlPackage.exe utility
- Host: GitHub
- URL: https://github.com/borispinsky/Clone-database-with-schema-only-
- Owner: borispinsky
- Created: 2020-05-31T17:38:44.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-12-10T21:12:10.000Z (over 4 years ago)
- Last Synced: 2024-05-23T00:30:42.071Z (11 months ago)
- Language: PowerShell
- Size: 8.79 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- jimsghstars - borispinsky/Clone-database-with-schema-only- - Clone database with schema only using SqlPackage.exe utility (PowerShell)
README
# Clone-database-with-schema-only
Clone database with schema only using SqlPackage.exe utilityA few days ago one of my clients ask me to build a script that will clone database with schema only (with empty tables).
One of my options was to use SQL Server Management Objects (SMO) with .net or PowerShell, but it could be a tricky especially with all kind of object dependencies.
I was surprised to figure out that it’s could be much simpler with SqlPackage.exe!
It’s could be done with four simple steps in powershell, but first Download the latest version of SqlPackage.exe:
https://docs.microsoft.com/en-us/sql/tools/sqlpackage?view=sql-server-ver151. Create an empty database.
2. Create dacpac from you source database with Extract action.
3. Create TSQL script with Script action.
4. Run the script against your empty database.*** Disclaimer: this solution won’t work if you source database has orphaned users.