create database db;
use db;
select database();
create table t1(
id int PRIMARY key auto_increment,
last_name VARCHAR(15)
);
desc t1;
insert into t1(last_name)
values('Sam');
select * from t1;
insert into t1(id,last_name)
values(0,'Tom');
insert into t1(id,last_name)
values(null,'LiLi');
#开发中,一旦主键作用的字段上声明有自增列时,则我们在添加数据时,就不要给主键对应的字段去赋值
insert into t1(id,last_name)
values(-20,'Lucy');
#在alter table 时添加自增列(很少)
create table t2(
id int primary key,
last_name VARCHAR(10)
);
desc t2;
alter table t2 modify id int auto_increment;
#在alter table 时删除自增列
alter table t2 modify id int;
use atguigudb;
select last_name,salary from employees
where department_id=(
select department_id
from employees
where last_name='Zlotkey'
);
select employee_id,last_name,salary
from employees
where salary>(
select avg(salary)
from employees
);