posts - 431,  comments - 344,  trackbacks - 0
          公告
           Don't Repeat Yourself
          座右銘:you can lose your money, you can spent all of it, and if you work hard you get it all back. But if you waste your time, you're never gonna get it back.
          公告本博客在此聲明部分文章為轉摘,只做資料收集使用。


          微信: szhourui
          QQ:109450684
          Email
          lsi.zhourui@gmail.com
          <2006年11月>
          2930311234
          567891011
          12131415161718
          19202122232425
          262728293012
          3456789

          留言簿(15)

          隨筆分類(1019)

          文章分類(3)

          文章檔案(21)

          收藏夾

          Link

          好友博客

          最新隨筆

          搜索

          •  

          積分與排名

          • 積分 - 863946
          • 排名 - 44

          最新評論

          閱讀排行榜

          1. 刪除表的重復記錄
           
          如果記錄完全相同才算重復記錄 , 那么 : (sql server2000 下測試通過 )
           select distinct * into #tmpp from person
           delete from person
           insert into person select * from #tmpp
           drop table #tmpp
           
          如果有 id 主鍵 ( 數字 , 自增 1 的那種 ), 那么 :(sql server2000 下測試通過 )
           delete from person where id not in
           (select id=min(id) from person group by UserName)
          2.復制表(并且復制記錄)
            select * into persontwo from person(只復制表結構)
            insert into persontwo select UserName,Address,Content from person(插入記錄)
          3.獲取表中最小未使用的ID
            SELECT (CASE WHEN EXISTS(SELECT * FROM person b WHERE b.Id = 1) THEN MIN(Id) + 1 ELSE 1 END) as Id
           FROM  person
           WHERE NOT Id IN (SELECT a.Id - 1 FROM person a)

          4.delete from tablea & truncate table tablea的區別

            truncate語句執行速度快,占資源少,并且只記錄頁刪除的日志;
           delete對每條記錄的刪除均需要記錄日志

          posted on 2006-11-23 09:08 周銳 閱讀(305) 評論(0)  編輯  收藏 所屬分類: MySQLOracleSQL Server
          主站蜘蛛池模板: 深州市| 独山县| 康定县| 泾阳县| 科尔| 新宁县| 井陉县| 石河子市| 通州市| 昂仁县| 灵武市| 石城县| 修武县| 甘德县| 鲜城| 兰西县| 牡丹江市| 临江市| 南康市| 逊克县| 广宗县| 金阳县| 南漳县| 达州市| 泗洪县| 潞城市| 德庆县| 宁德市| 喀什市| 兴文县| 萍乡市| 武功县| 禹州市| 绵竹市| 新沂市| 娄底市| 元谋县| 湾仔区| 太仆寺旗| 珲春市| 谢通门县|