// Creation and Insertion
CREATE TABLE cars (
id SERIAL PRIMARY KEY,
name VARCHAR(50),
model VARCHAR(50),
year INT
);
INSERT INTO cars (name, model, year)
VALUES
('Ford', 'Mustang', 1969),
('Toyota', 'Corolla', 2020),
('Honda', 'Civic', 2018);
// Alter
// Add
alter table cars
add color varchar(10)
// color
alter table cars
rename column color to color_name
// drop
=
alter table cars
drop column color_name
// Distinct + Count
select distinct color from cars;
select count(distinct color) fromt cars;
// where
select name, model from cars
where name = 'Ferrari'
// Order by
select * from cars
order by name;
// Limit
select * from cars
limit 2; // give me the two records
// Limit + offset
select * from cars
limit 2 offset 20; // guve me two records starting from 21
// Always use these ** Safely
// Updating cars [update/set]
update cars
set model='GT69', color='Yellow'
where name = 'Ford'
returning *; // return affected rows
// delete
delete from cars
where name ='Ford' and year = 1971;