zoukankan      html  css  js  c++  java
  • sql常用语句

    1.创建数据库:create database dbname;

    2.删除数据库:drop database dbname;

    3.备份数据库:

     创建备份的设备:use master exec sp_addumpdevice 'disk', 'test', 'c:\mssql7backup\1.dat'

     开始备份数据库:backup database pubs to test

    4.修改数据库名称:sp_renamedb 'oldname', 'newname'

    5.创建表:

      create table tname(

        col1 type1[not null][primary key] ,

        col2 type2[not null]

      )

    6.删除表:

      drop table tname;

    7.增加一个列:

      alter table tname column col type;(列增加后不能删除,DB2中列增加后,数据类型也不能变)

    8.增加主键:

      alter table tname add primary key(col)

      删除主键:alter table tname drop primary key(col)

    9.创建索引:

      create[unique]index iname on tname(col....)

      删除索引:drop index iname(索引是不可以修改的,想修改必须删除后重新建立)

    10.创建视图:

      create view viewname as select statement

      删除视图:drop view viewname

    11.几个简单的sql语句

      选择:select *from table1 where 条件

      插入:insert into table1 values(条件)

      删除:delete from table1 where 条件

      更新:update tablename set field1=value1 where 条件

      查找:select *from table1 where field1 like '%value1%'--模糊查询

      排序:select *from table1 order by field1,field2[desc] 

      总数:select count as totalcount from table1

      求和:select sum(field1) as sumvalue from table1

      求平均:select vag(field1) as vagvalue from table1

      最大:select max(field1) as maxvalue from table1

      最小:select min(field1) as minvalue from table1

    12.查询运算符

        A: UNION 运算符
        UNION 运算符通过组合其他两个结果表(例如 TABLE1 和 TABLE2)并消去表中任何重复行而派生出一个结果表。                              B: EXCEPT 运算符
        EXCEPT 运算符通过包括所有在 TABLE1 中但不在 TABLE2 中的行并消除所有重复行而派生出一个结果表。
      C: INTERSECT 运算符
        INTERSECT 运算符通过只包括 TABLE1 和 TABLE2 中都有的行并消除所有重复行而派生出一个结果表。

       也可以参见连接 http://zhidao.baidu.com/question/207968435.html

  • 相关阅读:
    servlet
    反射
    网络通信协议
    线程安全,
    线程池, Callable<V>接口
    Thread类,Runnable 接口
    commons-IO
    序列化流与反序列化流,打印流
    转换流,Properties 集合
    缓冲流
  • 原文地址:https://www.cnblogs.com/snailjn/p/2875406.html
Copyright © 2011-2022 走看看