Skip to content
techsnow

Introduction

Creating Tables

Syntax:

CREATE TABLE students (
  id INTEGER PRIMARY KEY,
  name TEXT NOT NULL,
  city TEXT,
  marks INTEGER DEFAULT 0,
  joined DATE
);
Data typeStores
INTEGER / INTWhole numbers
DECIMAL(10, 2)Exact decimals, e.g. money
TEXT / VARCHAR(100)Text
DATE / TIMESTAMPDates and times
BOOLEANTrue / false
ConstraintMeaning
PRIMARY KEYUniquely identifies each row
NOT NULLMust have a value
UNIQUENo two rows can share the value
DEFAULTValue used if none is given
FOREIGN KEYMust match an id in another table