@@ -22,12 +22,19 @@ DECLARE
22
22
@Seed int ,
23
23
@Increment int ,
24
24
@FirstColumn char (1 ) = ' ' ,
25
+ -- Variables for constraint
26
+ @ConstraintName varchar (128 ),
27
+ @ConstraintHold varchar (128 ),
28
+ @ConstraintType varchar (2 ),
29
+ -- Variables for Indexes
30
+ @IndexName varchar (128 ),
25
31
-- Variables for Data Migration
26
32
@InsertCols varchar (max ),
27
33
@InsertSql nvarchar (max )
28
34
29
35
Declare @Scripts Table (
30
36
Id int identity (1 ,1 ) primary key ,
37
+ ScriptType varchar (50 ),
31
38
TableName varchar (128 ),
32
39
SqlStatement varchar (max ),
33
40
SchemaName varchar (128 )
@@ -53,7 +60,7 @@ where type_desc = 'SQL_LOGIN'
53
60
54
61
INSERT INTO @Scripts
55
62
(
56
- TableName,
63
+ ScriptType,
57
64
SqlStatement,
58
65
SchemaName
59
66
)
@@ -71,7 +78,8 @@ order by create_date asc
71
78
72
79
While EXISTS (SELECT [Name] FROM #Tables)
73
80
BEGIN
74
- SELECT @TableObjectId = [object_id],
81
+ SELECT TOP 1
82
+ @TableObjectId = [object_id],
75
83
@TableName = [Name],
76
84
@SchemaName = [SchemaName]
77
85
FROM #tables;
@@ -174,21 +182,29 @@ BEGIN
174
182
SET @SQL = ' CREATE TABLE ' + @SchemaName + ' .' + @TableName + ' (' + @SQL + ' )' ;
175
183
176
184
IF @DropAndRecreate = 1
177
- INSERT INTO @Scripts (TableName, SqlStatement)
185
+ INSERT INTO @Scripts
186
+ (
187
+ ScriptType,
188
+ TableName,
189
+ SqlStatement
190
+ )
178
191
VALUES (
179
192
180
193
' Alter' ,
194
+ @TableName,
181
195
' DROP TABLE ' + @SchemaName + ' .' + @TableName
182
196
)
183
197
184
198
INSERT INTO @Scripts
185
- (
186
- TableName,
187
- SqlStatement,
188
- SchemaName
189
- )
199
+ (
200
+ ScriptType,
201
+ TableName,
202
+ SqlStatement,
203
+ SchemaName
204
+ )
190
205
VALUES
191
206
(
207
+ ' Table' ,
192
208
@TableName,
193
209
@SQL,
194
210
@SchemaName
0 commit comments