Skip to content

Commit 6b53fcc

Browse files
committed
add schemas to sp_doc
1 parent dc5b6e3 commit 6b53fcc

File tree

9 files changed

+113
-14
lines changed

9 files changed

+113
-14
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 John McCall
3+
Copyright (c) 2021 John McCall
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

appveyor/sqlcover/[dbo].[sp_doc]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Version: 20210629
2121

2222
MIT License
2323

24-
Copyright (c) 2020 John McCall
24+
Copyright (c) 2021 John McCall
2525

2626
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
2727
documentation files (the "Software"), to deal in the Software without restriction, including without limitation

appveyor/sqlcover/[dbo].[sp_estindex]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Version: 20210405
2525

2626
MIT License
2727

28-
Copyright (c) 2020 John McCall
28+
Copyright (c) 2021 John McCall
2929

3030
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
3131
documentation files (the "Software"), to deal in the Software without restriction, including without limitation

appveyor/sqlcover/[dbo].[sp_sizeoptimiser]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Version: 20210622
2323

2424
MIT License
2525

26-
Copyright (c) 2020 John McCall
26+
Copyright (c) 2021 John McCall
2727

2828
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
2929
documentation files (the "Software"), to deal in the Software without restriction, including without limitation

docs/sp_doc.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ red tape that third party applications often require.
2727

2828
It documents:
2929

30+
* Schemas
3031
* Tables
3132
* Triggers
3233
* Default Constraints

install_dba-multitool.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Version: 20210629
8989
9090
MIT License
9191
92-
Copyright (c) 2020 John McCall
92+
Copyright (c) 2021 John McCall
9393
9494
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
9595
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -2236,7 +2236,7 @@ Version: 20210405
22362236
22372237
MIT License
22382238
2239-
Copyright (c) 2020 John McCall
2239+
Copyright (c) 2021 John McCall
22402240
22412241
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
22422242
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -3619,7 +3619,7 @@ Version: 20210622
36193619
36203620
MIT License
36213621
3622-
Copyright (c) 2020 John McCall
3622+
Copyright (c) 2021 John McCall
36233623
36243624
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
36253625
documentation files (the "Software"), to deal in the Software without restriction, including without limitation

sp_doc.sql

Lines changed: 103 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
SET NOCOUNT ON;
12
SET ANSI_NULLS ON;
23
GO
34

@@ -89,7 +90,7 @@ Version: 20210629
8990
9091
MIT License
9192
92-
Copyright (c) 2020 John McCall
93+
Copyright (c) 2021 John McCall
9394
9495
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
9596
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -236,9 +237,6 @@ BEGIN
236237
WHERE [name] = DB_NAME();
237238
' +
238239

239-
/****************************
240-
Generate markdown for tables
241-
****************************/
242240
--Variables
243241
+ N'DECLARE @ObjectId INT,
244242
@IndexObjectId INT,
@@ -249,6 +247,107 @@ BEGIN
249247
DECLARE @KeyColumns NVARCHAR(MAX),
250248
@IncludeColumns NVARCHAR(MAX);';
251249

250+
/*****************************
251+
Generate markdown for schemas
252+
*****************************/
253+
--Build table of contents
254+
SET @Sql = @Sql + N'
255+
INSERT INTO #markdown (value)
256+
VALUES (''----'')
257+
,(CONCAT(CHAR(13), CHAR(10), ''## Schemas''))
258+
,(CONCAT(CHAR(13), CHAR(10), ''<details><summary>Click to expand</summary>'', CHAR(13), CHAR(10)));' +
259+
260+
+ N'INSERT INTO #markdown (value)
261+
SELECT CONCAT(''* ['', [name], ''](#'', REPLACE(LOWER([name]), '' '', ''-''), '')'')
262+
FROM [sys].[schemas]
263+
WHERE [schema_id] < 16384
264+
AND [name] NOT IN (''sys'', ''guest'', ''INFORMATION_SCHEMA'')
265+
ORDER BY [name] ASC;' +
266+
267+
--Object details
268+
+ N'DECLARE [obj_cursor] CURSOR
269+
LOCAL STATIC READ_ONLY FORWARD_ONLY
270+
FOR
271+
SELECT [schema_id]
272+
FROM [sys].[schemas]
273+
WHERE [schema_id] < 16384
274+
AND [name] NOT IN (''sys'', ''guest'', ''INFORMATION_SCHEMA'')
275+
ORDER BY [name] ASC;
276+
277+
OPEN [obj_cursor]
278+
FETCH NEXT FROM [obj_cursor] INTO @ObjectId
279+
WHILE @@FETCH_STATUS = 0
280+
BEGIN
281+
282+
INSERT INTO #markdown
283+
SELECT CONCAT(CHAR(13), CHAR(10), ''### '', SCHEMA_NAME(@ObjectId));' +
284+
285+
--Main Extended Property (@ExtendedProperty)
286+
+ N'
287+
IF EXISTS (SELECT * FROM [sys].[schemas] AS [s] WITH(NOLOCK)
288+
INNER JOIN [sys].[extended_properties] AS [ep] WITH(NOLOCK) ON [s].[schema_id] = [ep].[major_id]
289+
WHERE [s].[schema_id] = @ObjectId
290+
AND [ep].[minor_id] = 0 --On the object
291+
AND [ep].[class] = 3 --Schema
292+
AND [ep].[name] = @ExtendedPropertyName)
293+
BEGIN;
294+
INSERT INTO #markdown (value)
295+
VALUES (CONCAT(CHAR(13), CHAR(10), ''| '', @ExtendedPropertyName COLLATE DATABASE_DEFAULT, '' |''))
296+
,(''| --- |'');
297+
298+
INSERT INTO #markdown (value)
299+
SELECT CONCAT(''| '', REPLACE(REPLACE(REPLACE(REPLACE(CAST([ep].[value] AS NVARCHAR(4000)), ''|'', @PipeHTMLCode COLLATE DATABASE_DEFAULT), CHAR(13) + CHAR(10), @BreakHTMLCode COLLATE DATABASE_DEFAULT), ''`'', @TickHTMLCode COLLATE DATABASE_DEFAULT), '']'', @RightBracketHTMLCode COLLATE DATABASE_DEFAULT) COLLATE DATABASE_DEFAULT, '' |'')
300+
FROM [sys].[schemas] AS [s] WITH(NOLOCK)
301+
INNER JOIN [sys].[extended_properties] AS [ep] WITH(NOLOCK) ON [s].[schema_id] = [ep].[major_id]
302+
WHERE [s].[schema_id] = @ObjectId
303+
AND [ep].[minor_id] = 0 --On the object
304+
AND [ep].[class] = 3 --Schema
305+
AND [ep].[name] = @ExtendedPropertyName;
306+
END;';
307+
308+
--All Extended Properties (non-@ExtendedProperty)
309+
IF @AllExtendedProperties = 1
310+
BEGIN;
311+
SET @Sql = @Sql + N'
312+
IF EXISTS (SELECT * FROM [sys].[schemas] AS [s] WITH(NOLOCK)
313+
INNER JOIN [sys].[extended_properties] AS [ep] WITH(NOLOCK) ON [s].[schema_id] = [ep].[major_id]
314+
WHERE [s].[schema_id] = @ObjectId
315+
AND [ep].[minor_id] = 0 --On the object
316+
AND [ep].[class] = 3 --Schema
317+
AND [ep].[name] <> @ExtendedPropertyName)
318+
BEGIN;
319+
INSERT INTO #markdown (value)
320+
VALUES (CONCAT(CHAR(13), CHAR(10), ''#### '', ''Extended Properties''))
321+
,(CONCAT(CHAR(13), CHAR(10), ''| Name | Value |''))
322+
,(''| --- | --- |'');
323+
324+
INSERT INTO #markdown (value)
325+
SELECT CONCAT(''| '', [ep].[name], '' | '', REPLACE(REPLACE(REPLACE(REPLACE(CAST([ep].[value] AS NVARCHAR(4000)), ''|'', @PipeHTMLCode COLLATE DATABASE_DEFAULT), CHAR(13) + CHAR(10), @BreakHTMLCode COLLATE DATABASE_DEFAULT), ''`'', @TickHTMLCode COLLATE DATABASE_DEFAULT), '']'', @RightBracketHTMLCode COLLATE DATABASE_DEFAULT) COLLATE DATABASE_DEFAULT, '' |'')
326+
FROM [sys].[schemas] AS [s] WITH(NOLOCK)
327+
INNER JOIN [sys].[extended_properties] AS [ep] WITH(NOLOCK) ON [s].[schema_id] = [ep].[major_id]
328+
WHERE [s].[schema_id] = @ObjectId
329+
AND [ep].[minor_id] = 0 --On the object
330+
AND [ep].[class] = 3 --Schema
331+
AND [ep].[name] <> @ExtendedPropertyName
332+
ORDER BY [ep].[name] ASC;
333+
END;';
334+
END;
335+
336+
SET @Sql = @Sql + N'
337+
FETCH NEXT FROM obj_cursor INTO @ObjectId;
338+
339+
END;
340+
CLOSE obj_cursor;
341+
DEALLOCATE obj_cursor;' +
342+
343+
--End collapsible schema section
344+
+ N'INSERT INTO #markdown
345+
VALUES (CONCAT(CHAR(13), CHAR(10), ''</details>''));';
346+
--End markdown for schemas
347+
348+
/****************************
349+
Generate markdown for tables
350+
****************************/
252351
--Build table of contents
253352
SET @Sql = @Sql + N'
254353
IF EXISTS (SELECT 1 FROM [sys].[tables] WHERE [type] = ''U'' AND [is_ms_shipped] = 0)
@@ -2101,7 +2200,6 @@ BEGIN
21012200
,@TickHTMLCode
21022201
,@RightBracketHTMLCode
21032202
,@BreakHTMLCode;
2104-
21052203
END;
21062204
GO
21072205

sp_estindex.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Version: 20210405
105105
106106
MIT License
107107
108-
Copyright (c) 2020 John McCall
108+
Copyright (c) 2021 John McCall
109109
110110
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
111111
documentation files (the "Software"), to deal in the Software without restriction, including without limitation

sp_sizeoptimiser.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ Version: 20210622
128128
129129
MIT License
130130
131-
Copyright (c) 2020 John McCall
131+
Copyright (c) 2021 John McCall
132132
133133
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
134134
documentation files (the "Software"), to deal in the Software without restriction, including without limitation

0 commit comments

Comments
 (0)