### DBML import example with tables, enum, and Ref Source: https://drawsql.app/docs/import-dbml Paste this DBML into DrawSQL to generate a diagram with tables, relationships, enums, and notes. The example shows two tables, an enum, and a Ref: relationship. DrawSQL auto-detects the format and resolves column types for the target DBMS. ```dbml Table users { id int [pk, increment] email varchar [unique, not null] created_at timestamp } Table posts { id int [pk, increment] user_id int [not null] title varchar status post_status } Enum post_status { draft published } Ref: posts.user_id > users.id ``` -------------------------------- ### Sample export output with CREATE TABLE and ALTER TABLE Source: https://drawsql.app/docs/export-to-sql-ddl Sample output of a DrawSQL export. Shows CREATE TABLE statements for each table, primary keys added inline, and foreign keys added as ALTER TABLE statements at the end so tables can be created in any order. ```sql CREATE TABLE `regions`( `region_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `region_name` VARCHAR(25) NULL ); CREATE TABLE `countries`( `country_id` CHAR(2) NOT NULL, `country_name` VARCHAR(40) NULL, `region_id` INT NOT NULL ); ALTER TABLE `countries` ADD PRIMARY KEY(`country_id`); CREATE TABLE `departments`( `department_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `department_name` VARCHAR(30) NOT NULL, `location_id` INT NULL ); ALTER TABLE `countries` ADD CONSTRAINT `countries_region_id_foreign` FOREIGN KEY(`region_id`) REFERENCES `regions`(`region_id`); ``` -------------------------------- ### Run exported SQL with mysql, psql, or sqlcmd Source: https://drawsql.app/docs/export-to-sql-ddl Run the exported .sql file against an empty database using the command-line client for your DBMS. Replace USERNAME, DATABASE, SERVER, and other placeholders with your own values. ```bash # MySQL / MariaDB mysql -u USERNAME -p DATABASE < export.sql # PostgreSQL psql -d DATABASE -f export.sql # SQL Server sqlcmd -S SERVER -d DATABASE -i export.sql ``` -------------------------------- ### pg_dump Export Schema for Hosted PostgreSQL with Connection String Source: https://drawsql.app/docs/import-from-ddl For a hosted database, pass the connection string instead of the database name. ```bash pg_dump "postgresql://user:password@host:5432/dbname" --schema-only > schema.sql ``` -------------------------------- ### Sample Laravel migration export for employees and regions tables Source: https://drawsql.app/docs/export-to-laravel-migrations Sample Laravel migration files generated by DrawSQL's Laravel Migrations export. Each table is self-contained in its own migration class with a filename matching Laravel's convention. The employees migration disables foreign key constraints during creation and includes foreign key references; the regions migration is simpler and includes a down method. ```php integer('employee_id', 11)->primary()->autoIncrement(); $table->string('first_name', 20)->nullable()->default(null); $table->string('last_name', 25); $table->string('email', 100); $table->string('phone_number', 20)->nullable()->default(null); $table->date('hire_date'); $table->integer('job_id', 11); $table->foreign('job_id')->references('job_id')->on('jobs'); $table->decimal('salary', 8, 2); $table->integer('manager_id', 11)->nullable()->default(null); $table->foreign('manager_id')->references('employee_id')->on('employees'); $table->integer('department_id', 11)->nullable()->default(null); $table->foreign('department_id')->references('department_id')->on('departments'); }); Schema::enableForeignKeyConstraints(); } /** * Reverse the migrations. */ public function down(): void { Schema::dropIfExists('employees'); } }; ``` ```php integer('region_id', 11)->primary()->autoIncrement(); $table->string('region_name', 25)->nullable()->default(null); }); } /** * Reverse the migrations. */ public function down(): void { Schema::dropIfExists('regions'); } }; ``` -------------------------------- ### pg_dump Export Schema for PostgreSQL Source: https://drawsql.app/docs/import-from-ddl Use this structure-only dump. It excludes owner and privilege statements. ```bash pg_dump --schema-only --no-owner --no-privileges DATABASE > schema.sql ``` -------------------------------- ### Embed SQL DDL in a DrawSQL URL Source: https://drawsql.app/docs/embed-diagram-in-url Use the #ddl= parameter to embed a CREATE TABLE statement in a DrawSQL URL. The SQL is parsed and visualized automatically. Add ?driver=pgsql or ?driver=sqlsrv to parse for PostgreSQL or SQL Server; MySQL is the default, and auto-detection occurs if no driver is specified. ```url https://drawsql.app/draw#ddl=CREATE%20TABLE%20users%20(id%20BIGINT%20PRIMARY%20KEY,%20email%20VARCHAR(255)%20NOT%20NULL); ``` -------------------------------- ### Regenerate Rails schema with bin/rails db:schema:dump Source: https://drawsql.app/docs/import-rails-schema Run this command in your Rails app to regenerate db/schema.rb from the current database. Rails keeps the file current on every migration, but this command forces a fresh dump. ```shell bin/rails db:schema:dump ``` -------------------------------- ### mysqldump Export Schema for MySQL/MariaDB Source: https://drawsql.app/docs/import-from-ddl Use this structure-only dump to avoid data rows. It excludes comments and exports the database schema to schema.sql. ```bash mysqldump --no-data --skip-comments -u USERNAME -p DATABASE > schema.sql ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.