SQL常用语句--增删改查

查全部: select * from <tablename>;
条件查询:select <filed> from <tablename> where <field>=<key>;
带有函数查询: select count(*) from <tablename>;
模糊查询: select <field> from <tablename> where <field> like ‘%value%’;


添加库: create database <databasename>;
创建新表: create table <tablename> (col1 type1, col2, ...); 主键自增: create table test1(id int primary key auto_increment,name varchar(20))auto_increment=1;
插入数据: insert into <tablename>(field1,field2……) values(value1,value2………);
增加一列: alter table <tablename> add column <colname> <coltype>;
添加主键: alter table <tablename> add primary key(col);


更新: update <tablename> set <field>=<value> where <条件>;


删除库: drop database <databasename>;
删除表: delete from <tablename> where <条件>;(会留下日志文件,能被还原修复)
                      truncate table <tablename>;(不会留下日志文件,不能被还原修复)


子句:

where子句:= , > , < , <>(不等于) , >= , <=
order by子句:asc (升序) , desc(降序)


AbelChe wechat
扫码加微信
Donate here!!!
0%