MySQL的一些语句

1、新建数据库并指定编码(避免乱码问题)

UTF-8:

create database test(数据库名) default character set utf8 collate utf8_general_ci;
GBK:

create database test(数据库名) default character set gbk collate gbk_chinese_ci;

2、查询表结构

Show columns from user(表名);

3、增加字段(布尔类型可用tinyint)

Alter table user(表名) add column  username(字段名) int not null default 0 after  account(字段名,在哪个字段后面);

4、删除非空约束

Alter table user(表名) modify username(字段名,该字段没有唯一索引)  varchar(100)(根据原来的写即可)  null;

5、添加自增的设置

已建表,未建字段

alter table table(表名) add id(字段名) int auto_increment primary key;
已建表,已建字段

alter table table(表名) change id(原字段名) newId(新字段名) int auto_increment primary key(PK如已设置不需添加);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值