首页 小组 文章 相册 留言本 用户 搜索 我的社区 在线学堂 商城 购物车 支付钱包

[打卡]auto_increment

2024-05-28 10:13:01
0
239


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
);
评论
意见反馈