6

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.

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Yes, it is. Just paste the create statement you have into a query window and execute it.

4 Comments

do you have to have an active connection to do that? right now Im not actually connected to a database because I'm trying to design the schema before updating my database.
Just create another 'dummy' database, for your test and schmera changes.
Ok, that's a different question - your original question asked if it was possible 'to create the table' - obviously you have to have a connection to the database if you want to create a table in that database. So what you want is a way to parse the create statement and convert it into a local schema description... I don't know of a way to do that, though it may be possible.
basically I'm just looking for an easier way to create tables in my Model instead of typing out every single column

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.