Schema (DDL)
Learn SQL schema (ddl) with practical examples and guided drills on dbSyntax.
Start with Schema (DDL)Schema (DDL)
Data Definition Language: the statements that change the shape of the database rather than the rows in it. Create and drop tables, add and r...
CREATE TABLE
Define a new table: a name, a list of columns with types, and any constraints (primary key, not null, defaults, foreign keys). Most of the d...
ALTER TABLE ADD COLUMN
Add a column to an existing table without rebuilding it. The new column appears at the end, exists for every existing row (filled with NULL ...
ALTER TABLE RENAME
Rename a table or one of its columns. The data, indexes, and constraints stay in place; only the identifier changes. Cheap to run, surprisin...
DROP TABLE
Remove a table and every row inside it. Permanent, fast, and takes its indexes, constraints, and triggers with it. The single statement most...
PRIMARY KEY
The column (or combination of columns) that uniquely identifies every row. Implicitly NOT NULL and UNIQUE, and on most engines automatically...
FOREIGN KEY
Declare that a column in one table must match a primary key (or unique key) in another. The database refuses to insert a child row whose par...
CREATE INDEX
Build a secondary lookup structure that lets the engine find rows by a column (or set of columns) without scanning the whole table. Indexes ...
CREATE VIEW
Save a query as a named, queryable object. A view stores no data; it stores the definition. Each time you select from it, the engine substit...