CREATE DATABASE test;
use test;
CREATE TABLE student (
id int AUTO_INCREMENT,
name varchar(255),
address varchar(255),
city varchar(255),
salary int,
PRIMARY KEY (id)
);
INSERT INTO student VALUES (1, '刘一', '郑十家隔壁', '河南', 313);
INSERT INTO student VALUES (2, '陈二', '李四家隔壁', '安徽', 2023);
INSERT INTO student VALUES (3, '张三', '白娘子家隔壁', '杭州', 11);
ALTER TABLE student ADD COLUMN age int(10) DEFAULT 18;
select * from student;
-- CREATE TABLE person LIKE student;
-- INSERT INTO person select * from student;
-- select * from person;
-- CREATE TABLE children select * from student WHERE id = 2;
-- select * from children;
CREATE TABLE children (
id int AUTO_INCREMENT,
remark varchar(2048) DEFAULT '备注',
PRIMARY KEY (id)
);
-- INSERT INTO children VALUES (1, '你好啊');
-- INSERT INTO children VALUES (2, '不承担VB就是VB');
-- select * from children;
-- 联结查询:连接数据的桥梁
-- select a.name,b.remark from student a JOIN children b on a.id = b.id;
-- 子查询:嵌套查询的力量
-- select * from student where salary > (select AVG(salary) from student);
-- 视图:简化复杂查询
-- CREATE VIEW high_earners AS
-- select name, salary from student where salary > 1000;