举个栗子:
SHOW COLUMNS FROM ldcode
结果输出如图
pg✿ SELECT * FROM INFORMATION_SCHEMA.COLUMNS T WHERE T.TABLE_CATALOG='用户角色名' AND TABLE_NAME='表名称'
举个栗子:
SELECT table_schema,table_name,column_name,udt_name,character_maximum_length,data_type,ordinal_position
FROM information_schema.columns t
WHERE t.table_catalog='actuarial'
AND table_name ='ldcode'
order by ordinal_position
结果输出如图
使用mysql_fetch_field以下是例子.
mysql_fetch_field() 可以用来从某个查询结果中取得字段的信息。如果没有指定字段偏移量,则下一个尚未被 mysql_fetch_field() 取得的字段被提取。
对象的属性为:
name - 列名
table - 该列所在的表名
max_length - 该列最大长度
not_null - 1,如果该列不能为 NULL
primary_key - 1,如果该列是 primary key
unique_key - 1,如果该列是 unique key
multiple_key - 1,如果该列是 non-unique key
numeric - 1,如果该列是 numeric
blob - 1,如果该列是 BLOB
type - 该列的类型
unsigned - 1,如果该列是无符号数
zerofill - 1,如果该列是 zero-filled
=========
<?php
mysql_connect('localhost:3306', $user, $password)
or die("Could not connect: " . mysql_error())
mysql_select_db("database")
$result = mysql_query("select * from table")
or die("Query failed: " . mysql_error())
/* get column metadata */
$i = 0
while ($i <mysql_num_fields($result)) {
echo "Information for column $i:<br />\n"
$meta = mysql_fetch_field($result)
if (!$meta) {
echo "No information available<br />\n"
}
echo "<pre>
blob: $meta->blob
max_length: $meta->max_length
multiple_key: $meta->multiple_key
name: $meta->name
not_null: $meta->not_null
numeric: $meta->numeric
primary_key: $meta->primary_key
table:$meta->table
type: $meta->type
unique_key: $meta->unique_key
unsigned: $meta->unsigned
zerofill: $meta->zerofill
</pre>"
$i++
}
mysql_free_result($result)
?>
elect a.name as [column],b.name as typefrom syscolumns a,systypes b
where a.id=object_id('表名') and a.xtype=b.xtype
把“表名”替换成你要查看字段类型的表名,比如你要查看sysobjects表的各字段类型那么就是
select a.name as [column],b.name as type
from syscolumns a,systypes b
where a.id=object_id('sysobjects') and a.xtype=b.xtype
另外可以通过存储过程
exec sp_help 表名
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)