Basic SQL Statements

Data Definition Language (DDL)

CREATE DATABASE databasename;
DROP DATABASE databasename;
CREATE TABLE persons (
    person_id int,
    first_name varchar(255),
    last_name varchar(255),
    address varchar(255),
    city varchar(255)
);
ALTER TABLE persons
ADD email varchar(255);

ALTER TABLE persons
DROP COLUMN column_name;

ALTER TABLE persons
RENAME COLUMN person_id to pid;
DROP TABLE persons;

Data Manipulate Language (DML)

INSERT INTO persons (person_id, first_name, last_name, address, city)
VALUES (1, 'w', 'k', '11/22 soi3', 'bangkok');
SELECT * FROM persons LIMIT 10;
UPDATE persons
SET address = '15/22 soi3'
WHERE pid = 1;
DELETE FROM persons
WHERE pid = 1;

Last updated