2

I need to copy a table from one database to another. So I tried to query in SqlFiddle as follows but getting error

CREATE TABLE ForgeRock
    (`id` int, `productName` varchar(7), `description` varchar(55))
;

INSERT INTO ForgeRock
    (`id`, `productName`, `description`)
VALUES
    (1, 'OpenIDM', 'Platform for building enterprise provisioning solutions'),
    (2, 'OpenAM', 'Full-featured access management'),
    (3, 'OpenDJ', 'Robust LDAP server for Java')
;


CREATE TABLE ForgeRock1 AS SELECT * FROM ForgeRock

Error:

DDL and DML statements are not allowed in the query panel for MySQL; only SELECT statements are allowed. Put DDL and DML in the schema panel.

1
  • As the error states, SQLFiddle doesn't let you put CREATE TABLE statements in the box on the right. Put it in the box on the left. sqlfiddle.com/#!9/2f1c9/1 Commented Jul 3, 2015 at 5:24

2 Answers 2

1

You could also use mysqldump to dump a table into another database:

mysqldump -u<user> -p<password> <first_database> <table_name> | mysql -u<user> -p<password> <second_database>

Of course the second database must then first be created, which can be done using a command like:

mysql -u<user> -p<password> -e"CREATE DATABASE <second_database>"
Sign up to request clarification or add additional context in comments.

1 Comment

I think her question is more of a SQL Fiddle problem rather than a MySQL question. Too bad the title doesn't mention this.
0

You can use the MySQL INSERT INTO...SELECT syntax to achieve what you want.

CREATE TABLE ForgeRock1
    (`id` int, `productName` varchar(7), `description` varchar(55));

INSERT INTO ForgeRock1 SELECT * FROM ForgeRock

1 Comment

@LalitJadiya I updated my answer so that it runs in SQL Fiddle. Try again. You need to put the INSERT statement on the left.

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.