Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select Extended Property from SQL Server tables

I am writing a simple CMS for a client's database. There are 12 tables and they need to manage all of the data in 4 of them.

I set up a dynamic data project (Linq-to-SQL as that's what I'm most familiar with) and the first page makes all 12 tables available for edit as it should. These are in an enumerable list called visibleTables.

Next I went into SSMS and created an extended property called UserEdit and set it to 0 or 1 depending on whether the user should see it on that screen.

What I would love to do is filter the visibleTables list by that extended property but don't know how to.

I am able to see the list of tables and the property with this query:

select major_id, name, value
from sys.extended_properties
where name = 'UserEdit'

and I was going to loop through the visibleTables and remove the ones with 0s but I haven't figured that out either yet as the major_id doesn't seem to be a property I can find.

like image 249
nycdan Avatar asked Dec 17 '22 11:12

nycdan


1 Answers

Well, according to http://msdn.microsoft.com/en-us/library/ms177541.aspx, "major_id" for your class of extended properties (OBJECT_OR_COLUMN) really indicates the "object_id". So the following query would get you all the extended properties along with the tables they belong to:

select p.*, t.*
from sys.extended_properties p
inner join sys.tables t on p.major_id = t.object_id
where class = 1

You can filter it as you like, but let me know if you need help.

like image 106
Milimetric Avatar answered Jan 10 '23 04:01

Milimetric