Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 606
  • Last Modified:

in MSSQL, how can i retrieve accepted values as list equivalent to MySQL ENUM values? PHP preferred

I wish to (in PHP) dynamically retrieve a list of acceptable/available values for a column in a MSSQL database, for a field which has a Check Constraint to try to get functionality similar to MySQL ENUM data type.

Is there an easier way to do this?  with MySQL it's apparently quite simple (see code).  MSSQL has a string for the Check Constraints and takes a lot of effort to get to in the schema.

from the site http://dev.mysql.com/doc/refman/5.0/en/enum.html :
This is an extremely simple way to get the options from an enum into an array, here called $arryEnum
 
<?php
$result=mysql_query("SHOW COLUMNS FROM <table> LIKE '<column>'");
if( mysql_num_rows( $result ) > 0 )
{
   $row=mysql_fetch_row($result);
   preg_match_all("/'(.*?)'/", $row['Type'], $matches);
   $arryEnum= $matches[1];
}
?> 
 
The important bit is the regexp, which just matches anything in apostrophes.

Open in new window

0
labops
Asked:
labops
1 Solution
 
labopsAuthor Commented:
Nice.   That gets a little closer, I see the check constraint but not the parameters I'd set.  I was able to find the information from joining two information_schema tables.
Is there a better way to go about this from the start?  It sure would be nice to have that ENUM :(
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now