查询数据库中所以的数据库名:show databases;
创建一个数据库:create database 库名;(create database php;)
选中某个库:use 库名;(例如:use php;)
查看一个数据库中的所有表:show tables;
删除一个数据库:drop database 库名;(drop database php;)
创建一张简单的表:
create table class (
stu int,
name varchar(20),
age int,
area varchar(20)
);
create table score(
stu int,
name varchar(20),
ke varchar(10),
fen int
);
修改表名:rename table 原来的表名to 新表名;(rename table score to newscore;) 注意:数据库名是不能改的
删除一个表:drop table 表名;(drop table newscore;)
查询一个表的详细信息:desc 表名;(desc class;)
声明字符集:set names utf8;
插入信息:insert into 表名 (id,name,title) values (NULL,'asdasd','asdsad');
修改信息:update 表名 set name='阿萨德阿萨德发' where id=1; // 按什么修改自己定
创建一个数据库:create database 库名;(create database php;)
选中某个库:use 库名;(例如:use php;)
查看一个数据库中的所有表:show tables;
删除一个数据库:drop database 库名;(drop database php;)
创建一张简单的表:
create table class (
stu int,
name varchar(20),
age int,
area varchar(20)
);
create table score(
stu int,
name varchar(20),
ke varchar(10),
fen int
);
修改表名:rename table 原来的表名to 新表名;(rename table score to newscore;) 注意:数据库名是不能改的
删除一个表:drop table 表名;(drop table newscore;)
查询一个表的详细信息:desc 表名;(desc class;)
声明字符集:set names utf8;
插入信息:insert into 表名 (id,name,title) values (NULL,'asdasd','asdsad');
修改信息:update 表名 set name='阿萨德阿萨德发' where id=1; // 按什么修改自己定
删除信息:delete from 表名 where id=2; // 按什么删自己定
在一张表中增加一列(增加的列默认是在表的最后一列):alter table 表名 add 增加的字段名 字符类型; (例如:alter table class add age2 tinyint unsigned; )
可以用after 来声明新增的一列在哪一些后面
如果增加的列放到第一位 加 first alter table 表名 add 列声明 first(alter table boy add id int primary key auto_increment first;)
增加在某一个列后面:alter table boy add age tinyint unsigned not null default 22 after flower;
修改列
alter table 表名 change 被修改的列名 列声明;
alter table boy change height smallint not null default 180;
删除列
alter table 表名 drop 列名;
alter table boy drop id;
建立一张表和另一张表的结构一样:create table g2 like goods;
清空一张表:truncate g2;
五种子句是有顺序要求的:where,group,having,order by,limit按这个顺序