Schemas
the structure that was used to make the database, basically shows the commands that were used to make the DB
invoke by .schema
Normalizing
process of making the data more efficient, like separating out one giant table into multiple smaller tables through relating those tables.
CREATE TABLE
so you make a DB first sqllite3 sth.db, then u create a table through the sqllite or whatever software
CREATE TABLE riders (
"id",
"name"
);Data Types, Storage Classes
storage classes
- NULL
- INTEGER
- REAL(floats, decimals)
- TEXT
- BLOB(binary large objects(image, audio whatever file))
Data Types
Storage Classes have data types, Integer has 0-byte, 2-byte etc… INTEGERS.
Type Affinity:
Each column has a type affinity that it tries to convert other values to. type affinities are the same as storage classes.
how to make tables with types:
CREATE TABLE riders (
"id" INTEGER,
"name" TEXT
);Table Constraints
CREATE TABLE riders (
"id" INTEGER,
"name" TEXT,
PRIMARY KEY("id")
);
CREATE TABLE stations (
"id" INTEGER,
"name" TEXT,
"line" TEXT,
PRIMARY KEY("id")
);
CREATE TABLE visits (
"rider_id" INTEGER,
"station_id" INTEGER,
FOREIGN KEY("rider_id") REFERENCES "riders"("id"),
FOREIGN KEY("station_id") REFERENCES "stations"("id")
);Column Constraints
CHECKDEFAULTUsing default value if none is supplied(null by default)NOT NULL- can be used to require values for new entires?
UNIQUE
CREATE TABLE riders (
"id" INTEGER,
"name" TEXT,
PRIMARY KEY("id")
);
CREATE TABLE stations (
"id" INTEGER,
"name" TEXT NOT NULL UNIQUE,
"line" TEXT NOT NULL,
PRIMARY KEY("id")
);
CREATE TABLE visits (
"rider_id" INTEGER,
"station_id" INTEGER,
FOREIGN KEY("rider_id") REFERENCES "riders"("id"),
FOREIGN KEY("station_id") REFERENCES "stations"("id")
);Altering Tables
DROP TABLE
just delete a table
ALTER TABLE "VISITS"
RENAME TO "SWIPES"
ADD COLUMN "SWIPETYPE" TEXT;you can also just open the .schema file and just change the values from there instead of running these commands.