数据库指令

总结一些操作代码

create

create database [数据库名];

create table [表名称];

insert

insert into [表名称] values(内容);
insert into [表名称] (表的某个列名1,列名2…) values(内容); #常用于跳过某些字段,直插入()内的字段

select

select * from [表名称];
select * from [表名称] where [关键词] #查找所有存在[关键词]的表的内容

select * from [表名称] where [表名称] = [关键词] #在特定的表中查找

select [列名] from [表名称] #只展示这一[列名]

select [函数名]; #select curdate();

select bin( [列名] ) from [表名]; #2进制方式输出
select oct( [列名] ) from [表名]; #十进制
select hex( [列名] ) from [表名]; #16进制

drop

drop database [数据库名]
drop table [表名];
drop index [索引名] on [表名]; #删除索引

show

show tables; #展示当前数据库中的所有表
show tables from [数据库名]; #展示[数据库名]中的所有表
show create table [表名称]; #展示[表名称]的详细信息

show index from [表名]; 或 show keys form [表名] #查看键的约束名

desc

decs [表名称]; #展示表内容

delete

delete from [表名] where [列名] = [选择条件]; #删除指定列

alter

alter table [表名] modify [列名][类型]; #修改默认值、自增长和非空

alter table [表名] add constraint [约束名] [| primary key|foreign key] [列名] #新增主键,外键,唯一键

alter table tablename alter index index_name INVISIBLE; #隐藏索引

ALTER TABLE tablename ALTER INDEX index_name VISIBLE; #取消隐藏

update

UPDATE tablename SET field1 = value1, field2 = value2, field3 = value3, …, fieldn = valuen WHERE CONDITION; #更新数据

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值