Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create table structure without copying data from database table?

Tags:

sql

mysql

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?

like image 707
user3355518 Avatar asked Jun 06 '26 02:06

user3355518


2 Answers

CREATE TABLE new_table AS (SELECT * FROM old_table where 0=1);
like image 126
dcp Avatar answered Jun 07 '26 17:06

dcp


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

like image 37
mahbub_siddique Avatar answered Jun 07 '26 19:06

mahbub_siddique



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!