Data Definition Language (DDL) is a subset of SQL (Structured Query Language) used to define and modify database and structure. It includes commands for creating, altering, and deleting database objects like , indexes, and views. The basic queries used in DDL are: , , DROP, and TRUNCATE. There are also a couple of SQLite specific queries that you might use: .TABLE and .
The CREATE command is usually used to create a new . The basic syntax for the CREATE command is: CREATE TABLE tablename ( column1 datatype, column2 datatype ); For example, to create a table called Employees, you could use: CREATE TABLE Employees ( EmployeeID int, FirstName varchar(255), LastName varchar(255), BirthDate date ); The ALTER command is used to modify existing database . For example, you can add a new column by using: ALTER TABLE Employees ADD Email varchar(255);.
The DROP command is used to delete from the database, such as using: DROP TABLE Employees; to delete the Employee table. In contrast, the TRUNCATE command is used to delete all data inside a table, but not the itself. For instance, you can clear the contents of the Employee table using: TRUNCATE TABLE Employees. The .table command in SQLite is used to list all in the current database.
The PRAGMA table_info statement in SQLite is used to retrieve information about the columns in a specified . When you execute PRAGMA table_info(table_name), it returns a result set with information about the column ID, name, data type, whether they can be NULL, and other properties. This command is particularly useful for understanding the of a table, including details about each column such as cid, name, type, notnull, dflt_value, and pk.