DDL


Things to know before going into DDL queries:
Primary key:
It is a column or set of columns which has unique records within the table.
*primary key be NULL
*A table should have only one primary key.

Foreign Key :
It is the column which links two Tables.
*Foreign keys depend on the primary key of another table.
*A table can have any number of foreign keys
*Table with primary key is called as parent and table with the foreign key is called as child.

DDL Queries:
Creating a database:
create database coffee_store;

Creating Tables:
create table products(
id int auto_increment primary key,
name varchar(30),
price decimal());


Create table customers(
id int auto_increment primary key,
first_name varchar(30),
last_name varchar(30),
gender enum('m','f'),
phone_number
varchar(11));


create table orders(
id int auto_increment primary key,
product_id int,
customer_id int,
order_time datetime,
foreign key(product_id) references products(id), foreign
key(customer_id) references customers(id));

How to add or remove column from a Table:
alter table products
add column coffee_origin varchar(30);


alter table products
drop column coffee_origin;