Update from Sync Service
This commit is contained in:
55
数据库/循环批量删除数据库表.md
Executable file
55
数据库/循环批量删除数据库表.md
Executable file
@@ -0,0 +1,55 @@
|
||||
--创建临时表
|
||||
```sql
|
||||
create table #Man(
|
||||
```
|
||||
id int identity(1,1),
|
||||
tbName nvarchar(50)
|
||||
) --往临时表插入数据
|
||||
```sql
|
||||
insert into #Man
|
||||
select name from sys.tables
|
||||
where create_date<='2018-03-10 15:36:35.687' and name not in ('DeviceNetState','EphInfo','FilterStatistic','UserInfo','AlmInfo')
|
||||
```
|
||||
order by create_date desc
|
||||
|
||||
--确认
|
||||
```sql
|
||||
select * from #Man
|
||||
|
||||
```
|
||||
commit
|
||||
rollback
|
||||
begin tran
|
||||
|
||||
|
||||
--定义循环变量
|
||||
```sql
|
||||
declare @i int
|
||||
set @i = 1
|
||||
declare @count int
|
||||
select @count = count(*) from #Man
|
||||
|
||||
```
|
||||
--print @count
|
||||
|
||||
```sql
|
||||
declare @str nvarchar(500)
|
||||
declare @tb nvarchar(50)
|
||||
|
||||
```
|
||||
while(@i <= @count) begin
|
||||
|
||||
```sql
|
||||
select @tb = isnull(tbName, '') from #Man where id = @i
|
||||
```
|
||||
--循环执行语句
|
||||
```sql
|
||||
set @str = 'drop table [' + @tb+ ']'
|
||||
```
|
||||
exec(@str)
|
||||
|
||||
```sql
|
||||
set @str = ''
|
||||
set @i = @i + 1
|
||||
```
|
||||
end
|
||||
Reference in New Issue
Block a user