Create a Data Dictionary, from System views

OlaSa

New Member
Joined
Mar 22, 2015
Messages
23
I would like to use PowerQuary to get All TableCatalogues, TableNames and ColumnNames on an SQL Server, to create a "Data Dictionary".
Is it possible to do that?

I have tried to
1. First get a list of all TableCatalogues,
2. then create a Function for one TableCatalogue, and
3. then add a Column.
...but failed.


----
SELECT TABLE_CATALOG, TABLE_NAME, COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Have a look how this works:

Code:
let
    Quelle = Sql.Databases("YourServerName"),
    Budget1 = Quelle{[Name="YourDBName"]}[Data],
    MergeSchema = Table.NestedJoin(Budget1,{"Item"},Sql.Database("srvsql2", "Budget", [Query="SELECT * FROM INFORMATION_SCHEMA.TABLES"]),{"TABLE_NAME"},"NewColumn",JoinKind.LeftOuter),
    ShowCatalog = Table.ExpandTableColumn(MergeSchema, "NewColumn", {"TABLE_CATALOG"}, {"TABLE_CATALOG"}),
    ColNames = Table.AddColumn(ShowCatalog, "ColNames", each Table.ColumnNames([Data])),
    ShowColNames = Table.ExpandListColumn(ColNames, "ColNames")
in
    ShowColNames
 
Upvote 0
This how we solved the DataDictionary question:
This Table contains 3 columns: DatabaseName, TableName, ColumnName
Enjoy. //Ola.S


--- HumanityTaxes paid - please improve


Code:
USE [QX_YYYOAS]
GO
/****** Object:  StoredProcedure [dbo].[p_CT_DataDictionary]    Script Date: 2016-04-01 12:57:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[p_CT_DataDictionary]
as

if exists(select 1 from sys.tables where name = 'DataDictionary')
drop table DataDictionary

CREATE TABLE [dbo].[DataDictionary](
[DatabaseName] [sysname] NOT NULL,
[TABLE NAME] [sysname] NULL,
[COLUMN NAME] [sysname] NULL
)

exec sp_MSforeachdb '
USE [?]; 
insert into QX_YYYOAS..DataDictionary
SELECT  
''?'' AS [DatabaseName], 
T.NAME AS [TABLE NAME], C.NAME AS [COLUMN NAME]
FROM SYS.tables AS T
JOIN SYS.columns AS C
ON T.object_id  =C.object_id
JOIN SYS.TYPES AS P
ON C.SYSTEM_TYPE_ID=P.SYSTEM_TYPE_ID
WHERE T.schema_id=1
'
 
Upvote 0

Forum statistics

Threads
1,215,355
Messages
6,124,468
Members
449,163
Latest member
kshealy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top