Here i have an usable code for all u:
I wanted to know if a field is nullable or if it's defined as a primary key, here are those functions definitions:
*Aditional Notes:
if any of the tables are replicated in another database exactly , this code will not work well.
//-----to know if a field is nullable-------
function mssql_field_nullable($ip,$user,$pass,$table,$field)//starting from 1st field
{
$conn=mssql_connect($ip,$user,$pass)or die;
mssql_select_db('master');
$result=mssql_query("SELECT syscolumns.isnullable
FROM sysobjects INNER JOIN
syscolumns ON sysobjects.id = syscolumns.id WHERE sysobjects.name ='$table' AND syscolumns.isnullable = 1");
$x=mssql_num_rows($result);
mssql_close($conn);
return ($x==1?1:0);
}
//-------to know if a field is a primary key-------
function mssql_field_key($ip,$user,$pass,$table,$field)//starting from 1st field
{
$conn=mssql_connect($ip,$user,$pass)or die;
mssql_select_db('master');
$result=mssql_query("SELECT sysindexkeys.colid FROM sysobjects INNER JOIN sysindexkeys ON sysobjects.id = sysindexkeys.id WHERE sysobjects.name ='$table' AND sysindexkeys.colid = $field");
$x=mssql_num_rows($result);
mssql_close($conn);
return ($x==1?1:0);
}
by R.M.R.A