MySQL
来源:互联网 发布:最优化计算方法专业 编辑:程序博客网 时间:2024/06/05 05:12
1.alter 操作表字段
(1)添加新字段
alter table 表名 add 字段名 字段类型;
//alter table tb_admin add email varchar(50) not null;
(2)修改字段名称
alter table 表名 change 旧字段名 新字段名 字段类型;
//alter table tb_admin change email Email varchar(50);
(3)修改字段类型
alter table 表名 modify 字段名 字段类型;
//alter table tb_admin modify Email varchar(30);
(4)删除字段
alter table 表名 drop 字段名;
//alter table tb_admin drop Email;
2.alter 索引操作
(1)增加索引
alter table 表名 add index 索引名 (字段名1,字段名2.....);
//alter table tb_admin add index asd (id,user);
(2)删除索引
alter table 表名 drop index 索引名;
//alter table student drop index asd;
(3)查看某个表的索引
show index from 表名;
//show index from tb_admin;
(4)增加唯一限制条件的索引
alter table 表名 add unique 索引名(字段名);
//alter table tb_admin add unique ID(id);
3.主键操作
(1)增加主键
alter table 表名 add primary key(字段名);
//alter table tb_admin add primary key(id);
(2)删除主键
alter table 表名 drop primary key;(主键不是自动增长情况下)
//alter table tb_admin drop primary key;
alter table 表名 modify 字段 字段类型, drop primary key;(主键是自动增长情况下)
//alter table tb_admin modify id int, drop primary key;
4.更改表名
rename table 旧表名 to 新表名;
//rename table tb_admin to tb_users;
5.删除表
drop table 表名;
//drop table tb_user;
6.插入记录insert
insert into 数据表名(column_name1,column_name2,column_name3...)values(value1,value2,value3...);
//insert into tb_user(id,user,password,time,email)values(1,'小米','123','2001-01-01','123@QQ.com');
7.查询数据库记录select
select selection_list //要查询的内容,选择那些列
from 数据表名 //指定数据表
where primary_constraint //查询时需要满足的条件,行必须满足的条件
group by grouping_cloumns //如何对结果进行分组
order by sorting_cloumns //如何对结果进行排序
having secondary_constraint //查询时满足的第二个条件
limin count //限定输出的查询结果
//select * from tb_user;
8.修改记录update
update 数据表名 set column_name1=new_value1,column_name2=new_value2......where condition;
//update tb_user set password='321' where id=1;
9.删除记录delete
delete from 数据表名 where condition;
//delete from tb_user where id=1;
(1)添加新字段
alter table 表名 add 字段名 字段类型;
//alter table tb_admin add email varchar(50) not null;
(2)修改字段名称
alter table 表名 change 旧字段名 新字段名 字段类型;
//alter table tb_admin change email Email varchar(50);
(3)修改字段类型
alter table 表名 modify 字段名 字段类型;
//alter table tb_admin modify Email varchar(30);
(4)删除字段
alter table 表名 drop 字段名;
//alter table tb_admin drop Email;
2.alter 索引操作
(1)增加索引
alter table 表名 add index 索引名 (字段名1,字段名2.....);
//alter table tb_admin add index asd (id,user);
(2)删除索引
alter table 表名 drop index 索引名;
//alter table student drop index asd;
(3)查看某个表的索引
show index from 表名;
//show index from tb_admin;
(4)增加唯一限制条件的索引
alter table 表名 add unique 索引名(字段名);
//alter table tb_admin add unique ID(id);
3.主键操作
(1)增加主键
alter table 表名 add primary key(字段名);
//alter table tb_admin add primary key(id);
(2)删除主键
alter table 表名 drop primary key;(主键不是自动增长情况下)
//alter table tb_admin drop primary key;
alter table 表名 modify 字段 字段类型, drop primary key;(主键是自动增长情况下)
//alter table tb_admin modify id int, drop primary key;
4.更改表名
rename table 旧表名 to 新表名;
//rename table tb_admin to tb_users;
5.删除表
drop table 表名;
//drop table tb_user;
6.插入记录insert
insert into 数据表名(column_name1,column_name2,column_name3...)values(value1,value2,value3...);
//insert into tb_user(id,user,password,time,email)values(1,'小米','123','2001-01-01','123@QQ.com');
7.查询数据库记录select
select selection_list //要查询的内容,选择那些列
from 数据表名 //指定数据表
where primary_constraint //查询时需要满足的条件,行必须满足的条件
group by grouping_cloumns //如何对结果进行分组
order by sorting_cloumns //如何对结果进行排序
having secondary_constraint //查询时满足的第二个条件
limin count //限定输出的查询结果
//select * from tb_user;
8.修改记录update
update 数据表名 set column_name1=new_value1,column_name2=new_value2......where condition;
//update tb_user set password='321' where id=1;
9.删除记录delete
delete from 数据表名 where condition;
//delete from tb_user where id=1;
阅读全文
0 0
- Mysql
- MySql
- MYSQL
- MySQL
- mysql
- mysql
- mysql
- mysql
- Mysql
- Mysql
- mysql
- MySQL
- mysql
- Mysql
- mysql
- mysql
- mysql
- mySQL
- Android题目笔记(四)
- ES6-字符串扩展-at()和normalize()
- 容器的最后一个元素是否大于第一个元素
- AnkhSvn安装及使用
- 反射_泛型
- MySQL
- 输入经纬度获取地理位置
- 【队内胡策 10.26 】T1
- #define 和typedef的区别
- BP神经网络——Python 实现
- 扬帆起航
- Java5、Java6、Java6、Java7、Java8的新特性
- 全球NB-IoT发展面临六大挑战
- freemarker总结