SQL LESSON 25 OF 32

CREATE TABLE & constraints

CREATE TABLE defines columns and rules. PRIMARY KEY identifies a row, NOT NULL requires a value, UNIQUE rejects duplicates and CHECK validates a condition. SQLite foreign-key enforcement must be enabled per connection.

हिन्दी में समझें

CREATE TABLE कॉलम और नियम बनाता है। PRIMARY KEY पहचान, NOT NULL जरूरी मान, UNIQUE दोहराव और CHECK शर्त जाँचता है। SQLite में foreign keys प्रति कनेक्शन चालू करें।

अभ्यास: goals(id INTEGER PRIMARY KEY, title TEXT NOT NULL) बनाएँ। id 1 और title Learn daily डालें, फिर SELECT करें।

Hinglish mein samjhein

CREATE TABLE columns aur rules define karta hai. PRIMARY KEY identity, NOT NULL required value, UNIQUE duplicates aur CHECK condition handle karta hai. SQLite foreign keys connection par enable karo.

Practice: goals(id INTEGER PRIMARY KEY,title TEXT NOT NULL) banao; 1, Learn daily insert karke select karo.

A small SQL example

CREATE TABLE notes(id INTEGER PRIMARY KEY,title TEXT NOT NULL);
INSERT INTO notes VALUES(1,'Learn SQL');
SELECT * FROM notes;

Examples use the fictional shop database bundled with the SQL playground: customers, products, orders, order_items and employees. The engine is SQLite; other SQL dialects may differ.

Try this example in the SQL playground →

Practise this idea

Create a table goals(id INTEGER PRIMARY KEY, title TEXT NOT NULL), insert id 1 and title Learn daily, then select it.

Check answer & explanation
CREATE TABLE goals(id INTEGER PRIMARY KEY,title TEXT NOT NULL); INSERT INTO goals VALUES(1,'Learn daily'); SELECT * FROM goals;

The table declaration defines the key and required text. INSERT creates one row, and SELECT verifies the saved values in the temporary database.

Stuck in the course? Choose Check answer for either the challenge or quiz. Read the explanation and continue to the next lesson at your own pace.

Check your understanding

Which constraint requires a value?

  1. NOT NULL
  2. ORDER BY
  3. AS
Check the quiz answer

NOT NULL

CREATE TABLE defines columns and rules. PRIMARY KEY identifies a row, NOT NULL requires a value, UNIQUE rejects duplicates and CHECK validates a condition. SQLite foreign-key enforcement must be enabled per connection.

References & corrections

Use the official SQLite documentation for full language rules. Read how these lessons are made and checked. Found a mistake? Report it to Excel Keys with this lesson URL and a reproducible example.

FROM LEARNING TO BUSINESS RESULTS

Need a dashboard for your team?

Excel Keys designs custom Excel and HTML dashboards around your own KPIs and Excel files. They run offline in the browser, so your data stays on your computer.