SQL - Clone DB table structure with or without data

0 votes
39 views
added Mar 27 in Database by lcjr Lieutenant (12,240 points)
Method 1: Clone Structure + Data

This will copy both the table structure and data from rsops to rsopsFeatured.

CREATE TABLE rsopsFeatured AS SELECT * FROM rsops;

🔹 This creates a new table rsopsFeatured with the same structure and copies all data.

 

Method 2: Clone Structure Only (No Data)

If you only want to copy the table structure without data:

CREATE TABLE rsopsFeatured LIKE rsops;

Then, insert only featured data:

 

INSERT INTO rsopsFeatured SELECT * FROM rsops WHERE is_featured = 1;

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...