Data Definition Language (DDL) (Slides)
Data Definition Language (DDL) (Slides)
2
SQL basics
Database schemas and tables
A database schema is a logical container that
Tables are the fundamental building blocks of a
houses these tables and provides a framework for
database schema and store data in rows and
classifying, ordering, and arranging them in
columns.
relation to one another.
TABLE A TABLE B
col1 col2 col3 col1 col2 col3
x 34 s x 34 s
y 73 m y 73 m
z 22 l z 22 l
w 12 m w 12 m
3
SQL basics
Database schemas and DDL
4
SQL basics
CREATE DATABASE
Syntax Example
5
SQL basics
CREATE TABLE
| The CREATE TABLE statement is used to create new tables. It specifies the structure of the
table, defining the columns and their data types.
Syntax Example
| When creating a table in SQL, we can apply various constraints to columns to enforce data integrity and
define rules for the values stored in those columns. Here are some commonly used constraints in SQL:
| The ALTER TABLE statement is used to modify the structure of an existing database object,
such as adding, modifying, or deleting columns in a table.
Syntax Examples
_To add a column_
ALTER TABLE table_name
ADD column_name datatype;
8
SQL basics
TRUNCATE TABLE
| The TRUNCATE TABLE statement is used to remove all data from a table, effectively resetting it
to an empty state. This operation is faster than deleting individual rows.
Syntax Example
9
SQL basics
DROP TABLE and DROP DATABASE
| The DROP statements are used to remove entire database objects, such as tables or schemas,
from the database.
Syntax Example
10