Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c8d9585

Browse files
committed
Adds Script Type for decision making in powershell script
1 parent fbb271f commit c8d9585

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

‎ExtractDB/Schema.sql

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,19 @@ DECLARE
2222
@Seed int,
2323
@Increment int,
2424
@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),
2531
--Variables for Data Migration
2632
@InsertCols varchar(max),
2733
@InsertSql nvarchar(max)
2834

2935
Declare @Scripts Table(
3036
Id int identity(1,1) primary key,
37+
ScriptType varchar(50),
3138
TableName varchar(128),
3239
SqlStatement varchar(max),
3340
SchemaName varchar(128)
@@ -53,7 +60,7 @@ where type_desc = 'SQL_LOGIN'
5360

5461
INSERT INTO @Scripts
5562
(
56-
TableName,
63+
ScriptType,
5764
SqlStatement,
5865
SchemaName
5966
)
@@ -71,7 +78,8 @@ order by create_date asc
7178

7279
While EXISTS (SELECT [Name] FROM #Tables)
7380
BEGIN
74-
SELECT @TableObjectId = [object_id],
81+
SELECT TOP 1
82+
@TableObjectId = [object_id],
7583
@TableName = [Name],
7684
@SchemaName = [SchemaName]
7785
FROM #tables;
@@ -174,21 +182,29 @@ BEGIN
174182
SET @SQL = 'CREATE TABLE ' + @SchemaName + '.' + @TableName + ' (' + @SQL + ')';
175183

176184
IF @DropAndRecreate = 1
177-
INSERT INTO @Scripts (TableName, SqlStatement)
185+
INSERT INTO @Scripts
186+
(
187+
ScriptType,
188+
TableName,
189+
SqlStatement
190+
)
178191
VALUES(
179192

180193
'Alter',
194+
@TableName,
181195
'DROP TABLE ' + @SchemaName + '.' + @TableName
182196
)
183197

184198
INSERT INTO @Scripts
185-
(
186-
TableName,
187-
SqlStatement,
188-
SchemaName
189-
)
199+
(
200+
ScriptType,
201+
TableName,
202+
SqlStatement,
203+
SchemaName
204+
)
190205
VALUES
191206
(
207+
'Table',
192208
@TableName,
193209
@SQL,
194210
@SchemaName

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /