查看编码:show create database web08
删除一个库 drop database 库名
查看当前正在操作的库 select database() 对表的操作: 创建一张表 create table 表名{ 字段 类型(长度)【约束】 字段 类型(长度)【约束】
}; 表单约束: 主键约束:primary key,要求被修饰的字段:唯一&非空 唯一约束:unique 非空约束:not null要求被修饰的字段非空
例子: CREATE TABLE USER( uid INT(32) PRIMARY KEY AUTO_INCREMENT, uname VARCHAR(32), upassword VARCHAR(32) ); 查看数据库表:show tables
查看表的结构: desc 表名 删除表:drop table
修改表: 添加一列: alter table user add 表名 字段名 类型(长度)[约束]
修改列的类型的(长度、约束) alter table 表名 modify 要修改的字段名 类型(长度、)约束
修改列名: alter table 表名 change 久列名 新列名 类型(长度) 例子: ALTER TABLE USER CHANGE uinfo new_uinfo VARCHAR(100) NULL;
删除表的列 alter table 表名 drop 列名 ALTER TABLE USER DROP new_uinfo;
修改表名: alter table 旧表名 to 新表名 例子:RENAME TABLE USER TO new_table
修改表的字符集: alter table 表名 character set 字符集
插入记录:insert
删除数据: delete from 表 where 条件 delete from 表 删除表中所有的内容
查询操作: select[distinct] *列名,列名 from 表名[where条件] 例子: 查询所有商品: select * from product; 2.查询商品名和商品价格 select pname,price from product; 3.查询所有商品信息使用表别名 select * from product as 4.使用别名查询商品名 select pname as p from product 5.去掉重复值(按照价格) select distinct(price) from product
6.将所有的商品价格+10进行显示 select pname,price+10 from product; 查询条件:
条件查询: 查询商品名称为“左慈”的商品信息 select * from product where pname="左慈"
模糊查询: 查询含有时的产品信息 select * from product where pname like '%士%'
1.cid分组,根据统计相同cid的商品数量 select cid ,count(*) from product group by cid;
查询总结: select distinct *|字段 from 表 where 查询条件 group by 分组字段 having 分组条件 order by 排序字段 ASC|desc 分组后,带有条件,只能使用条件