SQL 语句大汇总

数据库操作指南:SQL语法详解

按照顺序来

//创建数据库

create database wenda charset utf8;

//删除数据库

drop database wenda;

//创建表

create table hd_ask(asid int unsigned primary key auto_increment,answer int not null default 0);

unsigned 非负 , primary key 主键 , auto_increment自增 , not null 非空 , default 默认值

//删除表

drop table hd_ask;

//追加字段

alter table 表名 add 字段 [first | after 字段]

//删除字段

alter table 表名 drop 字段名

//修改表名

alter table 表名 rename 新表名

例:alter table hd rename houdunwang;将表hd 更名为houdunwang

或 rename hd to houdunwang

//修改字段同时更名

alter table 表名 change 旧字段 新字段 [ first | after 字段]

例: alter table cb change id cid int(10) ;修改字段ID,同时更改字段名

//修改字段

alter table 表名 modify 字段[first | after 字段]

例: alter table cb modify id int(8) after name;

//查询数据的方法

select * from hd_ask;
select asid,answer from hd_ask;
select asid,answer from hd_ask where asid=1;
select asid,answer from hd_ask where asid>1 limit 0,10;

//填加主键

例: alter table cb add primary key (id);添加主键id

注: 一个表只能有一个主键,所以如果原来存在主键要删除,如何删除看下

//删除主键

例: alter table hd drop primary key;删除主键

转载于:https://my.oschina.net/codegong/blog/357813

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值