What is a Database Definition Language?
This is the programming language used to construct and alter the design of tables contained within a database. The most common form of DDL is Structured Query Language(SQL).
This language is not used to directly alter the data stored within a table, rather it is used to construct the framework within which data is contained.
CREATE TABLE COMMAND
Example 1 – Simple Non Relational Table
CREATE TABLE users(firstname text, lastname text, age integer, date of birth date);
Example 2 – Create a table with a primary key
Example 3 – Create another table that references the primary from the other table
SQL Data Types
- Char – Fixed Length Text
- Varchar(255) – Variable Length (For SQLite use – Text)
- Integer – Store a whole number
- Boolean – Stores 1 or 0 for Boolean
- Real – Floating point number
- Date / Time – (SQLite has no date or time data type so use Text / Float / Integer and use something like Epoch Time)
ALTER TABLE COMMAND
ALTER TABLE username ADD COLUMN height real;
ALTER TABLE username MODIFY COLUMN height integer
ALTER TABLE username DROP COLUMN email;
DROP TABLE COMMAND
DROP TABLE users;