濮阳杆衣贸易有限公司

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

游標刪除多個表里臟數(shù)據(jù)的方法

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

第一種方法:

復制代碼 代碼如下:

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的臟數(shù)據(jù)

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的臟數(shù)據(jù)

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游標的使用/關(guān)閉/釋放/優(yōu)化小結(jié)
  • SQL Server遍歷表中記錄的2種方法(使用表變量和游標)
  • sqlserver中觸發(fā)器+游標操作實現(xiàn)
  • 教你怎么使用sql游標實例分享
  • SQL server使用自定義函數(shù)以及游標
  • sql 游標使用筆記
  • SQL Server的通用分頁存儲過程 未使用游標,速度更快!
  • sqlserver 函數(shù)、存儲過程、游標與事務(wù)模板
  • MSSQL 游標使用 心得
  • sqlserver 游標的簡單示例
  • SQL Server 游標語句 聲明/打開/循環(huán)實例

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

巨人網(wǎng)絡(luò)通訊聲明:本文標題《游標刪除多個表里臟數(shù)據(jù)的方法》,本文關(guān)鍵詞  游標,刪除,多個,表里,臟,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《游標刪除多個表里臟數(shù)據(jù)的方法》相關(guān)的同類信息!
  • 本頁收集關(guān)于游標刪除多個表里臟數(shù)據(jù)的方法的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    西和县| 张家口市| 察雅县| 桑日县| 平邑县| 紫阳县| 皋兰县| 交口县| 文安县| 泰安市| 江西省| 东乌| 丹棱县| 赞皇县| 梅州市| 方城县| 雷波县| 新沂市| 宝丰县| 新巴尔虎右旗| 满城县| 陇南市| 上蔡县| 偏关县| 高安市| 监利县| 克什克腾旗| 吴川市| 威信县| 象州县| 安多县| 武威市| 尚志市| 上蔡县| 新安县| 定南县| 长海县| 文成县| 商河县| 大邑县| 连州市|