MySQL Schema Duplicator
This SQL script duplicates a MySQL schema without referential integrity. It creates a copy of the schema by iterating over all tables in the source schema and creating and inserting them into the target schema. The copy process does not include foreign key constraints.
Prerequisites
- MySQL
- Administrative privileges
Usage
To use this script, simply call the duplicate_schema
stored procedure and pass in the source and target schema names as parameters. For example:
sql
CALL duplicate_schema('source_schema', 'target_schema');
Procedure Steps
- Declare cursor and handler
- Create target schema if it doesn't exist
- Get a list of tables in the source schema
- Loop through the tables and create and insert into corresponding tables in the target schema
- Drop any foreign key constraints on the new table
- Output to SQL
- Close the cursor
Limitations
This script does not copy foreign key constraints between tables. Therefore, the target schema will not have the same referential integrity as the source schema.
License
This script is licensed under the MIT License.