MySQL 一般操作语句

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

//选择数据库
use testdatabase;

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

//显示数据表机构
descrjbe test_table
//向数据表插入数据 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';
//排序 desc(降序) asc(升序)
select * from test_table order by age desc,score asc;
//清空数据表数据 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 tes_table rename to test_table

//修改数据表一列的列名和数据类型 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;
原文地址:https://www.cnblogs.com/nb08611033/p/8387573.html