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

SQL · Theory

CREATE Table

← All stacks

Theory

13/439

CREATE Table

CREATE TABLE students (roll INT PRIMARY KEY, name VARCHAR(50) NOT NULL, marks INT); draws the register: column names, types, and rules. PRIMARY KEY means each roll is unique and not NULL. NOT NULL on name means you cannot insert a student without a name.

Order: database selected (USE), then CREATE TABLE, then INSERT rows, then SELECT. Empty table is normal after CREATE — it is not an error.

CREATE TABLE marks (id INT PRIMARY KEY AUTO_INCREMENT, roll INT, subject VARCHAR(30), score INT, FOREIGN KEY (roll) REFERENCES students(roll)); now two tables are related.

Trap: no PRIMARY KEY. Trap: VARCHAR with no length in old habits. Trap: reserved words as column names (date, order) — use backticks or a better name (order_date).

On the example next to this theory — CREATE TABLE defines columns and constraints; then INSERT sample rows.

Diagram
CREATE TABLE students
  ┌──────┬────────┬───────┐
  │ roll │ name   │ marks │
  ├──────┼────────┼───────┤
  │  (empty until INSERT) │
  └──────┴────────┴───────┘
Exam tip

Show students(roll PK, name, marks). Say empty table after CREATE is OK.

CREATE Table — sample query

CREATE TABLE users (
  id INTEGER PRIMARY KEY,
  name TEXT NOT NULL,
  email TEXT UNIQUE
);
INSERT INTO users (id, name, email) VALUES (1, 'Asha', 'a@x.com');
SELECT * FROM users;

CREATE TABLE defines columns and constraints; then INSERT sample rows.

Short notes

  • DefCREATE TABLE name (columns + types + keys).
  • RulePRIMARY KEY on the id/roll. NOT NULL where required.
  • TrapNo key. Using reserved words as column names.

Questions

1

Write a tiny CREATE TABLE.

2

Why PRIMARY KEY?

13 / 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.