常用SQL语句整理

查看数据库:

show databases

选择数据库

USE database_name

表定义信息

 describe table_name

插入数据:

insert into table_name (filed_1 ... field_n)    values (value_1 ... value_n)

eg: insert into person_no (NAME,AGE)  values ('Tom',10) 

更新数据:

update table_name   set field_1 = value_1 ... filed_n = value_n where condition

eg: update person_no set AGE =  20 where NAME = 'Tom'

查询数据:

select * from table_name where condition

模糊查询:前匹配、后匹配和任意位置匹配

select * from table_name where field1 like ' %value1%'  / like 'value2%  /  like '%value3'

注:该查询语句效率较低

排序查询:升序和降序

select field_1, field_n  from table_name where condition order by field_name [ASC|DESC]

去重查询:

select distinct field_1, field_n from table_name

查询总数:

select count(*)/count(0) * from table_name

查询前100条数据:

select top 100 * from table_name

删除数据:

delete from table_name where condition

你可能感兴趣的:(常用SQL语句整理)