Question

I have a SQL Server database that holds a table where a varchar column has a check constraints on it to make sure only a few different words can be entered as a value (names).

Like this

CONSTRAINT chk_Names CHECK (name IN ('John', 'Eva', 'Carl', 'Fred'))

What I want do do is to populate a combobox in java with these names, and I don't want to manually enter them since they might change in the database. I want to populate it from metadata.

But I haven't been able to find a way to get the information from the database either with the INFORMATION_SCHEMA or sys.objects (or from DatabaseMetaData in java for that matter)

I'm quite new to SQL Server but is it possible to get that information somehow?

Regards /Fred

Was it helpful?

Solution

It sounds like you should move the list of names to a table. You're Java form could select the data from the table.

And, because the data can change, it will be better to update the table than to change the check constraint. You can change the check constraint to a foreign key constraint too.

You can also find the check-constraint definitions in INFORMATION_SCHEMA.CHECK_CONSTRAINTS. The expression is in the CHECK_CLAUSE column; and, you'll have to extract the values from the expression.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top