乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      SQL語句大全[基礎(chǔ)]

       昵稱8448908 2012-03-20

      SQL語句大全[基礎(chǔ)]

      1、說明:創(chuàng)建數(shù)據(jù)庫
      create datebase database-name
       


      2、說明:刪除數(shù)據(jù)庫
      drop database dbname


      3、說明:備份sqlserver
      --- 創(chuàng)建 備份數(shù)據(jù)的 device
      USE master
      EXEC sp_addumpdevice 'disk', 'testBack', 'c:\mssql7backup\MyNwind_1.dat'
      --- 開始 備份
      BACKUP DATABASE pubs TO testBack
       


      3-1、對數(shù)據(jù)庫進(jìn)行操作:
      分離數(shù)據(jù)庫
      sp_detach_db;
      附加數(shù)據(jù)庫
      sp_attach_db 后接表明,附加需要完整的路徑名
      3-2.如何修改數(shù)據(jù)庫的名稱:
      sp_renamedb 'old_name', 'new_name'


      4、說明:創(chuàng)建新表(SQL下要去掉[])
      create table tabname(col1type1 [not null] [primary key],col2 type2 [not null],..)

      根據(jù)已有的表創(chuàng)建新表:
      SQL:
      select   *   into   新表   from   表 –全復(fù)制含數(shù)據(jù)
      select   *   into   新表   from   表   where  1=2     --只要表結(jié)構(gòu)

      A:create table tab_new like tab_old (使用舊表創(chuàng)建新表)
      B:createtable tab_new as select col1,col2… from tab_old definition only


      5、說明:刪除新表
      drop table tabname
       


      6、說明:增加一個列
      Alter table tabname add字段名char(10)
      identity (1,1) –-從1自增1
      列增加后將不能刪除。DB2中列加上后數(shù)據(jù)類型也不能改變,唯一能改變的是增加varchar類型的長度。


      7、說明:添加主鍵Alter table tabname add primary key(col)
      說明:刪除主鍵:
      sp_helpconstraint table_name –得到約束名
      Alter table tabname drop primary key(上面得到的約束名) 


      8、說明:創(chuàng)建索引create[unique] index idxname on tabname(col….)
      刪除索引:drop index idxname
      注:索引是不可更改的,想更改必須刪除重新建。


      9、說明:創(chuàng)建視圖:create view viewname as select statement
      刪除視圖:drop view viewname


      10、說明:幾個簡單的基本的sql語句
      選擇:
      select * from table1 where 范圍
      插入:insert into table1(field1,field2)values(value1,value2)
      刪除:delete from table1 where 范圍
      更新
      :update table1 set field1=value1 where 范圍
      查找:select * from table1 where field1 like ’%value1%’---like的語法很精妙,查資料!
                  select * from table1 where field1 isno null
      排序:select * from table1 order by field1,field2desc
      總數(shù)select count as totalcount from table1
      SQL:  select count (value) as Tname from table_namewhere name=’x’
      求和select sum(field1) as sumvalue from table1
      SQL:  select sum(value) from table1
      平均:select avg(field1) as avgvalue from table1
      SQL:  select avg(value) from table1
      最大:select max(field1) as maxvalue from table1
      SQL:  select max(value) from table1
      最小select min(field1) as minvalue from table1
      SQL:  select min(value) from table1


      11、說明:幾個高級查詢運算詞


      A: union 運算符(去掉A與B中的重復(fù)行)

      UNION 運算符通過組合其他兩個結(jié)果表(例如 TABLE1 和 TABLE2)并消去表中任何重復(fù)行而派生出一個結(jié)果表。當(dāng) ALL 隨UNION 一起使用時(即UNION ALL),不消除重復(fù)行。兩種情況下,派生表的每一行不是來自 TABLE1 就是來自 TABLE2。
      例:
      select username from table1
      union
      select username fromtable2

      (僅返回table1與table2中共有的數(shù)據(jù))
      select username from table1

      union

      select username from table2

      (返回table1與table2中所有數(shù)據(jù),有重復(fù)的)


      B:except 運算符 (查A表,不顯示B表中有的)
      EXCEPT
      運算符通過包括所有在 TABLE1 中但不在TABLE2 中的行并消除所有重復(fù)行而派生出一個結(jié)果表。當(dāng) ALL 隨EXCEPT 一起使用時 (EXCEPT ALL),不消除重復(fù)行。
      例:
      select username from table1

      except

      select username from table2
      (以table2為條件,返回tabel1并且不在table2中的)


      C:intersect 運算符(返回A與B中都有的項)
      INTERSECT
      運算符通過只包括 TABLE1 和 TABLE2 中都有的行并消除所有重復(fù)行而派生出一個結(jié)果表。當(dāng) ALL 隨INTERSECT 一起使用時(INTERSECT ALL),不消除重復(fù)行。
      例:
      select username from table1

      intersect

      select username from table2
      (返回tabel1與table2共有的)
      注:使用運算詞的幾個查詢結(jié)果行必須是一致的。

       
      12、說明:使用外連接
      A、left (outer)join
      左外連接(左連接):結(jié)果集幾包括連接表的匹配行,也包括左連接表的所有行。
      SQL: select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a = b.c
      B:right (outer)join:
      右外連接(右連接):結(jié)果集既包括連接表的匹配連接行,也包括右連接表的所有行。
      C:full/cross (outer) join
      全外連接:不僅包括符號連接表的匹配行,還包括兩個連接表中的所有記錄。
      12、分組:Groupby:
           
      一張表,一旦分組 完成后,查詢后只能得到組相關(guān)的信息。
             組相關(guān)的信息:(統(tǒng)計信息) count,sum,max,min,avg  分組的標(biāo)準(zhǔn))
          在SQLServer中分組時:不能以text,ntext,image類型的字段作為分組依據(jù)
             在selecte統(tǒng)計函數(shù)中的字段,不能和普通的字段放在一起;

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多