Link to home
Start Free TrialLog in
Avatar of emi_sastra
emi_sastra

asked on

How to read rules created on SQL Server database from application?

Hi All,

Let's say I've created some rules inside SQL database.
Under Programmability, Rules.

I want to read it from my application to validate user input.

How could I do it?

Thank you.
Avatar of HainKurt
HainKurt
Flag of Canada image

what do you mean by "rules inside SQL database"?
ASKER CERTIFIED SOLUTION
Avatar of Dirk Strauss
Dirk Strauss
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of emi_sastra
emi_sastra

ASKER

Hi Dirk,

Great. But how to query specific database ?

Thank you.
sys.objects is part of each DB, and refers to its objects only. So you access it like any other table.
Qlemo is correct. If you had to run
SELECT * FROM sys.objects 

Open in new window

in a new query window for your selected database, you will see familiar results with the objects in the selected database. Look at the fields type and type_desc to identify what it returns.

I created the rule on a test database of mine.
User generated imageWhen I run the following SQL:
SELECT * 
	FROM sys.objects so
	JOIN sys.columns sc
		ON so.object_id = sc.rule_object_id
	WHERE 
		OBJECT_NAME(sc.object_id) = 'tblPeople' -- table name
		AND sc.name = 'age'  --column name

Open in new window

The results returned are
User generated image
Hi Dirk,

Thank very much for your help.