MySQL 操作语句

Posted 神马都是浮云

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL 操作语句相关的知识,希望对你有一定的参考价值。

//创建数据库(phpmysql语句结尾不用加;,因为PHP中MySQL语气每次只能执行一句)
create database testdatabase;

//选择数据库
use testdatabase;

//创建数据表
create table test_table(first_name varchar(30),last_name varchar(30));

//向数据表插入数据
insert into test_table(first_name,last_name)values(Sally,Jones);
//这个不太好
insert into test_table values(‘Sally‘,‘Jones‘);
//查询数据 select * from test_table; select first_name from test_table; select first_name from test_table where first_name=Sally; //清空数据表数据 delete from test_table; //删除数据表一行数据 delete from test_table where first_name=Sally or last_name=Jones; //删除数据表 drop table test_table; //删除数据库 drop database testdatabase; //为数据表增加一列 alter table test_table add id int; //为数据表增加一列,并设置为主键(不许为空,自增,放在表最前面) alter table test_table add id int not null auto_increment first, add primary key(id); //删除数据表中的一列 alter table test_table drop column first_name; //修改数据表一列的列名和数据类型 alter table test_table change column first_name middle_name char; //修改数据表一列的列名,位置 alter table test_table modify column first_name middle_name; alter table test_table modify column first_name first; alter table test_table modify column last_name after middle_name;

 



以上是关于MySQL 操作语句的主要内容,如果未能解决你的问题,请参考以下文章

mysql语句的相关操作整理

部分代码片段

SQL Select 语句的用法

[AndroidStudio]_[初级]_[配置自动完成的代码片段]

linux中怎么查看mysql数据库版本

[AndroidStudio]_[初级]_[配置自动完成的代码片段]