Industry: Healthcare IT
Platform: Microsoft SQL Server
- Project Title:
Automated T-SQL Script to Clone SQL Server Database and Relocate MDF/LDF Files
- Objective:
To create a reliable, script-based solution for cloning the emr4_newcustomer SQL Server database and preparing a new database instance for onboarding a new client, with controlled file placement for mdf and ldf.
- Project Description:
The client requested a
T-SQL script that would:
- a) Clone an existing EMR (Electronic Medical Records) database.
- b) Allow new .mdf and .ldf files to be stored in a custom directory (G:\data).
- c) Use an existing .bak file located in (G:\backups\full).
- d) Ensure that the database schema and data (if needed) were transferred.
After evaluating the task:
- a) An initial script using DBCC CLONEDATABASE was provided (schema-only copy).
- b) Upon further request, a second script using BACKUP and RESTORE DATABASEwas written to include data
- c) Instructions and a Loom video were also shared for GUI-based options using SQL Server Management Studio.
- Tools & Technologies Used:
- a) SQL Server Management Studio (SSMS)
- b) T-SQL Scripting
- c) DBCC CLONEDATABASE
- d) BACKUP / RESTORE DATABASE
- e) Windows File System for MDF/LDF location control
- Key Features Implemented:
- a) T-SQL script for cloning an existing database structure.
- b) Enhanced version with full database data cloning using backup-restore method.
- c) Manual guidance for file relocation (.mdf/.ldf) post-restore.
- d) Supportive video tutorial for GUI-based method.
- Challenges Faced & Solutions:
| Challenge |
Solution |
| Client wanted full data duplication, not just schema |
Delivered updated backup-restore-based T-SQL script |
| Requested file redirection to a custom path (G:\data) |
Explained SQL Server limitations for automatic path change; offered manual step |
| Client preferred not to share server access |
Delivered verified code to run independently with instructions |
- Outcome & Benefits:
- a) Client successfully cloned the production EMR database.
- b) New client database instance was created with expected structure and data.
- c) Client became confident in managing future clones using the script or SSMS.
- d) Maintained data security and operational independence for the client.
- Client Testimonial (Summary):
“It works well to clone the db. I can even do it from my software.”