Sqlsrv::dropAllTables()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Spatie\MigrateFresh\TableDroppers;
4
5
use Illuminate\Support\Facades\DB;
6
7
class Sqlsrv implements TableDropper
8
{
9
    private $dropScript = '
10
		while(exists(select 1 from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where CONSTRAINT_TYPE=\'FOREIGN KEY\'))
11
		begin
12
			declare @sql nvarchar(2000)
13
			SELECT TOP 1 @sql=(\'ALTER TABLE \' + TABLE_SCHEMA + \'.[\' + TABLE_NAME + \'] DROP CONSTRAINT [\' + CONSTRAINT_NAME + \']\')
14
			FROM information_schema.table_constraints
15
			WHERE CONSTRAINT_TYPE = \'FOREIGN KEY\'
16
			exec (@sql)
17
		end
18
		
19
		
20
		while(exists(select 1 from INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA != \'sys\'))
21
		begin
22
			declare @sql1 nvarchar(2000)
23
			SELECT TOP 1 @sql1=(\'DROP TABLE \' + TABLE_SCHEMA + \'.[\' + TABLE_NAME + \']\')
24
			FROM INFORMATION_SCHEMA.TABLES
25
			WHERE TABLE_SCHEMA != \'sys\'
26
			exec (@sql1)
27
		end';
28
29
    public function dropAllTables()
30
    {
31
        DB::unprepared($this->dropScript);
32
    }
33
}
34