CREATE TABLE defines a new table, with a name and a data type for each column:
CREATE TABLE Students (
StudentID INTEGER PRIMARY KEY,
Name VARCHAR(100) NOT NULL,
Email VARCHAR(150),
BirthDate DATE
);
DROP TABLE Students; deletes the table and its data. DROP TABLE IF EXISTS avoids an error if it does not exist.
💡 Key Takeaways: SQL CREATE TABLE
Mastering SQL CREATE TABLE helps you write clean and reliable SQL code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
SQL CREATE TABLE Code Example
SQL
CREATE TABLE Students (
StudentID INTEGER PRIMARY KEY,
Name VARCHAR(100) NOT NULL,
Course VARCHAR(50),
Fee DECIMAL(10, 2)
);
INSERT INTO Students (Name, Course, Fee) VALUES
('Ali', 'Python', 15000), ('Sara', 'SQL', 9000);
SELECT * FROM Students;
DROP TABLE IF EXISTS Students;
Free sign-in required · Google login available
SQL CREATE TABLE Practice Exercises
Check what you learned in “SQL CREATE TABLE”.
/ 3 solved
Fill in the blank
Create a new table.
Teachers (
TeacherID INTEGER PRIMARY KEY,
Name TEXT
);
✓ Correct!Not quite. Try again.
Multiple choice
Which statement deletes a table only if it exists?
✓ Correct!Not quite. Try again.
Code challenge
Create a table Cities with columns CityID INTEGER PRIMARY KEY and Name TEXT, insert 'Lahore' and 'Quetta', then select Name from Cities.
Write the code in the live editor. Your answer is checked automatically.