我从sp_helpconstraint iyas_grandtest那里得到这个信息。
constraint_name definition
iyas_grand_2317208971 PRIMARY KEY INDEX ( id) : CLUSTERED
iyas_grand_2317208972 UNIQUE INDEX ( unik) : NONCLUSTERED
iyas_grand_2317208973 UNIQUE INDEX ( comp_unik1, comp_unik2) : NONCLUSTERED我想提取:
如下所示:
id
注意,有时主键可以是主键索引( id,id2)。
我现在拥有的是缺陷(只检测到复合键的一个键,如果有_,则截断名称,即'comp_unik1‘变成'comp')。
$sql = sybase_query("sp_helpconstraint iyas_grandtest");
while( $row = sybase_fetch_assoc($sql) ) {
$txt= $row['definition'];
$re1='(PRIMARY)'; # Word 1
$re2='.*?'; # Non-greedy match on filler
$re3='(?:[a-z][a-z]+)'; # Uninteresting: word
$re4='.*?'; # Non-greedy match on filler
$re5='(?:[a-z][a-z]+)'; # Uninteresting: word
$re6='.*?'; # Non-greedy match on filler
$re7='((?:[a-z][a-z]+))'; # Word 2
if ($c=preg_match_all ("/".$re1.$re2.$re3.$re4.$re5.$re6.$re7."/is", $txt, $matches))
{
$word =$matches[2][0];
$keys = explode(",", $word);
}
}发布于 2011-12-27 02:13:00
你可以试着匹配:
^\w+\s+(?:PRIMARY KEY|UNIQUE) INDEX \(([^)]+)\)对于每一行,然后捕获$1,这是括号之间的内容,并使用explode,就像您已经在$1上做的那样。
https://stackoverflow.com/questions/8640575
复制相似问题