Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE PROCEDURE [dbo].[crud_watch_graph_getItems]
- @filters CRUDFilterParameter READONLY,
- @sort sql_variant,
- @direction nvarchar(8),
- @page INT,
- @pageSize INT,
- @username nvarchar(32)
- AS
- BEGIN
- -- filters...
- DECLARE @text nvarchar(128)=''
- SELECT @text = VALUE FROM @filters WHERE [KEY] = 'text'
- DECLARE @ids TABLE (id nvarchar(512))
- INSERT INTO @ids
- SELECT TABLE_NAME
- FROM INFORMATION_SCHEMA.TABLES t0
- WHERE TABLE_TYPE='BASE TABLE'
- AND @text<>'' AND TABLE_NAME LIKE '%'+@text+'%'
- -- SELECT 1
- SELECT t0.id id, t0.id name, '#f00' color, 'circle' TYPE, 6 dim,
- (
- STUFF((SELECT ', ' + COLUMN_NAME
- FROM INFORMATION_SCHEMA.COLUMNS
- WHERE TABLE_NAME = t0.id
- ORDER BY ORDINAL_POSITION
- FOR XML PATH('')), 1, 2, '')
- ) tip
- FROM @ids t0
- -- SELECT 2
- SELECT COUNT(*) FROM @ids
- -- SELECT 3
- SELECT 'graph' viewType,
- '{"contHeight": "1000px"
- }' graphOptions
- /*Select '' Title,
- '' ToolbarAdditional,
- '' GroupOperationsToolbar,
- '' EmptyText,
- '' FastCreateLinkText, '' FastCreateDialogHeader, '' FastCreateDialogPlaceholder,
- 0 FastCreateSearch, 0 FastCreateTextarea,
- 0 HideTitleCount,
- 0 DisableCellTitle,
- '10px' FontSize,
- '{filterCode}' FilterMakeup,
- 1 InstantFilter,
- */
- -- 4 SELECT Footer data or kanban/gantt data
- SELECT t1.[TABLE] nodeFrom, t1.referenced_table nodeTo, '#00f' color FROM (
- SELECT obj.name AS FK_NAME,
- sch.name AS [schema_name],
- tab1.name AS [TABLE],
- col1.name AS [COLUMN],
- tab2.name AS [referenced_table],
- col2.name AS [referenced_column]
- FROM sys.foreign_key_columns fkc
- INNER JOIN sys.objects obj
- ON obj.object_id = fkc.constraint_object_id
- INNER JOIN sys.TABLES tab1
- ON tab1.object_id = fkc.parent_object_id
- INNER JOIN sys.schemas sch
- ON tab1.schema_id = sch.schema_id
- INNER JOIN sys.COLUMNS col1
- ON col1.column_id = parent_column_id AND col1.object_id = tab1.object_id
- INNER JOIN sys.TABLES tab2
- ON tab2.object_id = fkc.referenced_object_id
- INNER JOIN sys.COLUMNS col2
- ON col2.column_id = referenced_column_id AND col2.object_id = tab2.object_id
- WHERE tab1.name IN (SELECT id FROM @ids) OR tab2.name IN (SELECT id FROM @ids)
- ) t1
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement