数据定义语言(DDL)
CREATE DATABASE IF NOT EXISTS my_test CHARACTER SET 'utf8';
SHOW DATABASES;
USE my_test;
SHOW TABLES;
SELECT DATABASE()
FROM dual;
SHOW TABLES FROM atguigudb;
ALTER DATABASE my_test CHARACTER SET 'gbk';
SHOW CREATE DATABASE my_test;
DROP DATABASE IF EXISTS my_test;
CREATE TABLE IF NOT EXISTS myempl_1
(
id INT,
emp_name VARCHAR(15),
hire_date DATE
);
DESC myempl_1;
SHOW CREATE TABLE myempl_1;
CREATE TABLE myempl_2
AS
SELECT employee_id, last_name, salary
FROM employees;
DESC myempl_2;
DESC employees;
SELECT *
FROM myempl_2;
CREATE TABLE myempl_3
AS
SELECT e.employee_id emp_id, e.last_name lname, d.department_name
FROM employees e
JOIN departments d ON d.department_id = e.department_id;
CREATE TABLE employee_blank
AS
SELECT *
FROM employees
WHERE 1 = 2;
SELECT *
FROM employee_blank;
ALTER TABLE myempl_1
ADD salary DOUBLE(10, 2);
ALTER TABLE myempl_1
ADD phone_number VARCHAR(20) FIRST;
ALTER TABLE myempl_1
ADD email varchar(45) AFTER emp_name;
ALTER TABLE myempl_1
MODIFY emp_name VARCHAR(25);
ALTER TABLE myempl_1
CHANGE salary month_salary double(10, 2);
ALTER TABLE myempl_1
DROP COLUMN email;
RENAME TABLE myempl_1
TO myemployee_1;
DROP TABLE IF EXISTS myemployee_1;
TRUNCATE TABLE myempl_3;
COMMIT;
SET AUTOCOMMIT = FALSE;
DELETE
FROM myempl_3
WHERE 1 = 1;
ROLLBACK;
SELECT *
FROM myempl_3;
COMMIT;
SET AUTOCOMMIT = FALSE;
TRUNCATE TABLE myempl_3;
ROLLBACK;
SELECT *
FROM myempl_3;