First things first: I am using Microsoft SQL Server Management Studio (if you need more information, just tell me).
Here is my problem: I have a really high number of tables and I am trying to bring some structure to it.
My team decided to 'just' add certain extended properties to each table:
- Name
- Date
- Link to Doku
Each table should have at these 3 ext. properties. And of course there should be an info at the value of each of them.
Now I am trying to use a script to get all the tables which do NOT have those extended properties.
So the result of the script should be:
A list of all tables which
- missing one or more of the "must have" extended properties
- missing the value of one or more of the "must have" extended properties
At the end a result table would be nice - something like
| TableName | Problem |
|---|---|
| Table_A | Missing ext. property |
| Table_B | missing value |
I tried things like
select t.name as tablename, p.*
from sys.tables t
left join sys.extended_properties p on t.object_id = p.major_id
to get a list of all tables and ext. properties.
But I have no clue to get the list I was talking about at the beginning.
Any ideas?
Chris
This query will return a row for each
TABLEin the database, with columns reporting the presence (or absence) of those named extended-properties, as well as an indication if the extended-properties exist but have an empty@value = N''string.DBFiddle example: https://dbfiddle.uk/r3lLCcR1
When...
Table_Ahas EPs for'Name','Date', and'Link'.Table_Bhas EPs for'Name'and'Date', but not'Link'. And the'Date'EP is an empty-string.Table_Chas no EPs....the result:
TableSchemaTableNameHasNameHasDateHasLinkHasNonemptyNameHasNonemptyDateHasNonemptyLinkdboTable_AdboTable_BdboTable_C