2012年11月24日土曜日

自分のテーブルデータを一括削除

とりあえず、単純なものを。メモっとかないと忘れてしまう・・・
use [DB]
go

declare cur_user_tables cursor for
select
  all_obj.name
from
  sys.all_objects as all_obj
  inner join sys.schemas s on
    s.name = 'dbo' and
    s.schema_id = all_obj.schema_id
where
  all_obj.type = 'U' and
  all_obj.is_ms_shipped = 0
;

declare @table_name varchar(max)
declare @sql varchar(max)

open cur_user_tables;

fetch next from cur_user_tables
  into @table_name;

while @@FETCH_STATUS = 0
begin
  set @sql = 'delete from ' + @table_name;
  print @sql
  execute(@sql)

  fetch next from cur_user_tables
    into @table_name;
end

close cur_user_tables;
deallocate cur_user_tables;

go

0 件のコメント:

コメントを投稿

SQL で MP4 をパース

SQL でビットマップ画像の2値化は4年位前に挑戦した。 最近、それの Impala 版 を作ったときに閃いた。 「再帰CTEがあるなら、mp4 もいけるんじゃないか」と。 やってみた。 use ragingo drop table video go create...