Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create tables in MySQL Workbench using a SQL statement?

I'm using MySQL Workbench to design a new schema and I have an exisiting create statement for a new table. Is it possible to use the create statement to create the table instead of manually writing out all the columns and types?

For example, here is my SQL:

CREATE TABLE IF NOT EXISTS `mydb`.`user` (
 `user_id` INT UNSIGNED NOT NULL,
 `last_updated` DATETIME NOT NULL DEFAULT now(),
 `user_stamp` INT UNSIGNED NOT NULL DEFAULT 1,
 `user_name` VARCHAR(15) NOT NULL,
 `company_code` INT UNSIGNED NOT NULL,
 `email` VARCHAR(50) NULL DEFAULT '',
 `active` CHAR(1) NULL DEFAULT 'Y',
 `first_name` VARCHAR(20) NULL,
 `last_name` VARCHAR(20) NULL,
 PRIMARY KEY (`user_id`),
 INDEX `fk__user__company_idx` (`company_code` ASC),
 CONSTRAINT `fk__user__company`
 FOREIGN KEY (`company_code`)
 REFERENCES `mydb`.`company` (`company_code`)
 ON DELETE CASCADE
 ON UPDATE NO ACTION 
);

I want to be able to run this statement somewhere in MySQL Workbench so the table gets added to my schema and then I use it in my diagram.

like image 677
Kristen Avatar asked Oct 18 '22 07:10

Kristen


1 Answers

You can save the CREATE TABLE statements to a file, then choose File > Import > Reverse Engineer MySQL Create Script... in Mysql Workbench (v. 8.0). If you have relations between tables Mysql Workbench should be able to guess it.

like image 159
sglessard Avatar answered Oct 21 '22 07:10

sglessard