常用SQL语句

1、创建数据库
    create database database_name

2、删除数据库
    drop database database_name

3、创建新表
    create table tablen_ame(col1 type1[not null][primary key],col2 type[not null],...)
    根据已有表来创建新表
    create table table_new like table_old
    create table table_new as select col1, col2,.. from table definition only

4、删除表
    drop table table_name

5、增加列
    alter table table_name add column col_name type
    
6、添加主键
    alter table table_name add primary key(col_name)
    alter table table_name drop primary key(col_name)

7、创建索引
    create [unique] index idx_name on table_ame(col...)

8、查询
    select * from table_name where 范围

9、插入
    insert into table_name(field1,filed2) values(value1,value2)

10、删除
    delete from table_name where 范围

11、更新
    update table_name set filed1=value1 where 范围

12、几个简单的函数
    select sum(filed1) as sum_value from table_mame
    select value(filed2) as avg_value from table_name
    select min(filed1) as min_value from table_name
    select max(filed1) as max_value from table_name

13、查询前10条
    select top 10 *from table_name
    随机选择10条记录
    select top 10 * from table_name order by newid()

14、in操作符
    select * from table_name where col_name in (value11,value2,...)

 

posted @ 2019-02-19 14:08  一沐春风  阅读(162)  评论(0编辑  收藏  举报