MySQL Review

check table & data syntax

Posted by Chauncey on May 13, 2020

Metadata

Create Table

create table employee (
  person_name char(10),
  street char(10),
  city char(10),
  salary real
);

Add Primary Key

alter table employee add primary key(person_name);

Add New Column

alter table employee add column salary real;

Delete Column

alter table employee drop city;

Drop Table

drop table employee;

Show table

desc employee;

Data

Show all data

select * from employee;

Add data

insert into employee values ('han mei', 'dagong rd', 'dalian', 6000), ('Li Lei', 'Hollywood Rd', 'LA');

Select data

find names of employees who live in Dalian

select person_name from employee where city = 'dalian';
select person_name from employee where street like 'Dagong rd';
select person_name from employee where salary > 10000;

Delete Data

delete from employee where street = 'Dagong rd';

Table with Foreign key

Cross-product