3

I was asked in a viva "how can you create a table structure without copying data from a database table?" I was quite sure with my answer. My answer was:`

CREATE TABLE new_table AS (SELECT *FROM old_table);

Was I right or wrong?

3
  • 1
    I think you are looking for create table like. Commented Feb 26, 2014 at 13:31
  • 1
    CREATE TABLE new_table AS (SELECT *FROM old_table WHERE 1=0); Commented Feb 26, 2014 at 13:33
  • see if this post helps ... stackoverflow.com/questions/233870/… Commented Feb 26, 2014 at 13:40

4 Answers 4

2
CREATE TABLE new_table AS (SELECT * FROM old_table where 0=1);
Sign up to request clarification or add additional context in comments.

Comments

1

No. Your answer is incorrect. You can use this SQL query.

CREATE TABLE *new_table* AS (SELECT *FROM *old_table* WHERE *statement=false*);

Like this an example is following:

CREATE TABLE *new_table* AS (SELECT *FROM *old_table* WHERE *1=2*);

I think it will serve your purpose...:P

Comments

0
CREATE TABLE new_table AS SELECT * FROM old_table where 0=1;

Here in where clause we can use any unequality statement like where 1=2,2=3..etc., which should inform optimizer this 'where' condition will definitely return false, thus preventing any data to be copied from old_table.

Comments

-1

if you are using workbench it has a option in left side of the screen "Data export" just click on it select the db you want to copy structure of and there will be a drop down option select "Dump structure only" and export to a folder.

import this file where ever you want using option data import restore and select path and type new schema name and import. you have new schema with the structure you want.

Comments

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.