我试图找出我试图合并到的表是否有一个identity
列(来自一个 php 应用程序)。正在构建的查询是:
USE dhs;
select COLUMN_NAME as name
from INFORMATION_SCHEMA.COLUMNS
where TABLE_SCHEMA = 'dbo'
and COLUMNPROPERTY(object_id(TABLE_NAME), COLUMN_NAME, 'IsIdentity') = 1
AND TABLE_NAME = 'orders'
如果我在 Management Studio 中运行它,我会得到id
(这是我所期望的)的返回值。但是,当我从我的应用程序运行相同的查询时,没有返回任何内容。我已经给了我的数据库用户完全权限,所以这不是权限问题。下面是我正在运行的 php(即使它应该返回 'id',它当前也返回 false):
$array = empty($array) ? $_POST : $array; //if no array is passed, use post
$info = self::information_schema($db, $schema, $table);
$clean = array(); //the hex-exscaped key values pairs that are matched against the database column names (so only items whose key matches a column name are used)
$primary = array();// ON section array
$update = array(); //the array for elements to update, each position is set to target.$k = source.$k
$insert = array(); //The insert string, which is essentially array_keys($clean) minus any identity field with source. prepended
$fields = array(); //fields to insert to with no source. prepended and no identity fields included
$query= "USE $db
select COLUMN_NAME as name
from INFORMATION_SCHEMA.COLUMNS
where TABLE_SCHEMA = '$schema'
and COLUMNPROPERTY(object_id(TABLE_NAME), COLUMN_NAME, 'IsIdentity') = 1
AND TABLE_NAME = '$table'"; //this gets the identity column of table it has one (to prevent trying to insert into an IDENTITY field)
$handle = sqlsrv_query(self::$conn, $query);
$value = sqlsrv_fetch_array($handle, SQLSRV_FETCH_NUMBERIC);
var_dump($value);
SQL Server 是否不允许您INFORMATION_SCHEMA
从 SSMS 外部进行选择?