mysql常用语句

一.准备阶段
#查看数据库
show databases;

#创建名为aaa的数据库编码为'utf8'
create database aaa character set 'utf8';

#选择数据库
use 数据库名;

#创建表
create table project_line(
    #主键自增
    id int primary key auto_increment comment '主键',
    (title)字段名  (varchar(100))字段类型 not null default ''(默认值为空字符) comment '字段注解',

    create_at datetime not null default current_timestamp comment '创建时间',
    update_at datetime not null default current_timestamp on update current_timestamp comment '更新时间',
    create_by bigint not null default 0 comment '创建人',
    update_by bigint not null default 0 comment '更新人',
    is_delete bigint not null default 0 comment '1为旧数据0为新数据',


) engine=innodb default charset=utf8 comment='给表添加注释';

二.查
#查看所有表
show 表名;

#查询所有字段
select * from 表名;

三.改


#修改字段值,将id为1的一条数据中的字段名1和字段名2进行修改
update 表名 set 字段名1='值1',字段名2='值2'  where id=1;

#修改字段类型
alter table 表名 modify column 字段名 类型 comment '注释';

#修改字段名称
alter table 表名 change 旧字段名 新字段名 新数据类型 comment '注释';

#插入字段,并设置默认值
alter table 表名 add column 字段名 类型 not null default 填入默认值 comment '注释';

四.删

#删除表内容并且使id从1开始
truncate table 表名;

五.增

#多行添加
insert into 表名(字段名1, 字段名2, 字段名3, 字段名4) values
  (字段名1添加的内容, 字段名2添加的内容, 字段名3添加的内容, 字段名4添加的内容),
  (字段名1添加的内容, 字段名2添加的内容, 字段名3添加的内容, 字段名4添加的内容),
  (字段名1添加的内容, 字段名2添加的内容, 字段名3添加的内容, 字段名4添加的内容);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值