PGoCareerGoCareer prep tools
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

SQL · Theory

Copy Table

← All stacks

Theory

21/439

Copy Table

CREATE TABLE students2 LIKE students; copies structure (columns, indexes) without rows. CREATE TABLE students2 AS SELECT * FROM students; copies data but may skip some indexes/PK details — check SHOW CREATE TABLE after.

INSERT INTO students2 SELECT * FROM students; fills a table that already exists.

Trap — AS SELECT then wondering why AUTO_INCREMENT / FKs vanished. LIKE then INSERT is cleaner for a clone.

On the example next to this theory: Copy Table: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

Exam tip

LIKE = structure. AS SELECT = data. Combine for a clone.

Copy Table — sample query

-- Copy Table
CREATE TABLE demo (
  id INTEGER PRIMARY KEY,
  label TEXT NOT NULL,
  qty INTEGER DEFAULT 0
);
INSERT INTO demo (id, label, qty) VALUES
  (1, 'alpha', 2),
  (2, 'beta', 5);
SELECT label, qty FROM demo WHERE qty >= 2 ORDER BY qty DESC;

Copy Table: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

Short notes

  • DefLIKE copies structure. AS SELECT copies data (check indexes).
  • RuleCREATE … LIKE then INSERT SELECT for a full clone.
  • TrapAS SELECT dropping keys you still needed.

Questions

1

Copy structure only?

21 / 439

P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.