婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > 游標刪除多個表里臟數據的方法

游標刪除多個表里臟數據的方法

熱門標簽:慶陽地圖標注 電銷外呼系統軟件功能 榕城市地圖標注 美團地圖標注商戶認證注冊 浙江穩定外呼系統供應商 北京400電話辦理多少錢 承德地圖標注公司名需要花錢嗎 咸陽電腦外呼系統運營商 怎么給高德做地圖標注

第一種方法:

復制代碼 代碼如下:

CREATE proc [dbo].[delAllRecord]
as
declare @tableName nvarchar(255)
declare @Sql nvarchar(255)

Declare curTable Cursor
        for select Table_Name from information_schema.tables where TABLE_TYPE='BASE TABLE'
Open curTable
Fetch Next From curTable Into @tableName

WHILE(@@FETCH_STATUS = 0)
        BEGIN
                set @Sql = N'delete from '+@tableName
                exec sp_executesql @sql
                Fetch Next From curTable Into @tableName
        end
CLOSE curTable
DEALLOCATE curTable


第二種方法:

復制代碼 代碼如下:


--declare test_cursor cursor scroll for

--select id,table_name from dbo.section_type

--open test_cursor

--declare @id int

--declare @table_name nvarchar(50)

--while @@fetch_status=0

--begin

--fetch next from test_cursor into @id,@table_name

--print @id

--print @table_name

--end

--close test_cursor

--deallocate test_cursor

 

--刪除projectrangtree的臟數據

delete from projectrangtree where deleteversion>0

delete from projectrangtree where type=3 and parentid not in(select id from projectrangtree where type=2)

delete from projectrangtree where type=4 and parentid not in(select id from projectrangtree where type=3)

delete from projectrangtree where type=5 and parentid not in(select id from projectrangtree where type=4)

 

--刪除section_settings的臟數據

delete from section_settings where parent_prj_tree_id not in(select id from projectrangtree)

 

--刪除各個表里的測點

declare @table_name varchar(50)

declare @sql nvarchar(500)--此處要注意,聲明的長度一定要夠

--declare @measuring_point_id nvarchar(500)

declare del_cursor cursor scroll for

select table_name from section_type

open del_cursor

fetch next from del_cursor into @table_name

--print @table_name

while (@@fetch_status=0)

begin

--print quotename(@table_name)

--set @measuring_point_id='select measuring_point_id from '+quotename(@table_name)

--exec sp_executesql @measuring_point_id

set @sql = 'delete from '+ quotename(@table_name) +' where measuring_point_id not in(select id from measuring_point_setting)'            

exec sp_executesql @sql

--delete from @table_name where measuring_point_id not in (select id from measuring_point_setting)

fetch next from del_cursor into @table_name

end

close del_cursor

deallocate del_cursor
 

--delete from (select talbe_name from section_type) where measuring_point_id not in (select id from measuring_point_setting)

您可能感興趣的文章:
  • SQL Server游標的使用/關閉/釋放/優化小結
  • SQL Server遍歷表中記錄的2種方法(使用表變量和游標)
  • sqlserver中觸發器+游標操作實現
  • 教你怎么使用sql游標實例分享
  • SQL server使用自定義函數以及游標
  • sql 游標使用筆記
  • SQL Server的通用分頁存儲過程 未使用游標,速度更快!
  • sqlserver 函數、存儲過程、游標與事務模板
  • MSSQL 游標使用 心得
  • sqlserver 游標的簡單示例
  • SQL Server 游標語句 聲明/打開/循環實例

標簽:新鄉 重慶 上海 昭通 呼和浩特 江蘇 貴州 拉薩

巨人網絡通訊聲明:本文標題《游標刪除多個表里臟數據的方法》,本文關鍵詞  游標,刪除,多個,表里,臟,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《游標刪除多個表里臟數據的方法》相關的同類信息!
  • 本頁收集關于游標刪除多個表里臟數據的方法的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 五家渠市| 都江堰市| 鲁甸县| 健康| 罗城| 福海县| 莱州市| 库尔勒市| 石楼县| 顺昌县| 长宁县| 城市| 龙山县| 淅川县| 大化| 阳原县| 娄底市| 扬州市| 饶阳县| 长汀县| 阿克苏市| 延寿县| 娄底市| 全州县| 印江| 达拉特旗| 重庆市| 望谟县| 鄯善县| 松潘县| 山阳县| 宜宾市| 稻城县| 绍兴县| 灵璧县| 阿合奇县| 石阡县| 太和县| 平潭县| 蒙自县| 天津市|