6个回答
展开全部
--通过如下语句得到当前Sql server中所有的数据的名称:
use master
select [name] from [sysdatabases] order by [name]
go
-- 查询数据库中的所有用户表
use [DBname]
select [id], [name] from [sysobjects] where [type] = 'u' order by [name]
--通过上面的查询的id,可以查出这个表中所有的字段,例如我们查询BaseData表中所有的字段,就可以通过下面的语句查出:
select [name] from [syscolumns] where [id] = 2087000699 order by [colid]
go
你所说的问题的语句是:
select [name], * from [syscolumns] order by [id]
use master
select [name] from [sysdatabases] order by [name]
go
-- 查询数据库中的所有用户表
use [DBname]
select [id], [name] from [sysobjects] where [type] = 'u' order by [name]
--通过上面的查询的id,可以查出这个表中所有的字段,例如我们查询BaseData表中所有的字段,就可以通过下面的语句查出:
select [name] from [syscolumns] where [id] = 2087000699 order by [colid]
go
你所说的问题的语句是:
select [name], * from [syscolumns] order by [id]
追问
mysql啊
追答
难道sql语句不是一样的写么?数据库不同,但是功能是一样的。mysql 通用 你试试这样写 应该是可以的。
参考资料: http://zhidao.baidu.com/question/217326277.html
展开全部
代码如下,不知你表如何,你自己作适当修改;
$sql="select * from table";
$query=mysql_query($sql);
while($field=mysql_fetch_field($query)){
$f.=$field->name;
}
echo $f;
这样就可以把这个表的所有字段名打印出来了
$sql="select * from table";
$query=mysql_query($sql);
while($field=mysql_fetch_field($query)){
$f.=$field->name;
}
echo $f;
这样就可以把这个表的所有字段名打印出来了
追问
只改表名吗????
我是说在数据库的客户端,我的是navicat。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<?php
$con = mysql_connect("localhost", "hello", "321");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db("test_db",$con);
$sql = "SELECT * from 表名";
$result = mysql_query($sql,$con);
while ($property = mysql_fetch_field($result))
{
echo "Field name: " . $property->name . "<br />";
echo "Table name: " . $property->table . "<br />";
echo "Default value: " . $property->def . "<br />";
echo "Max length: " . $property->max_length . "<br />";
echo "Not NULL: " . $property->not_null . "<br />";
echo "Primary Key: " . $property->primary_key . "<br />";
echo "Unique Key: " . $property->unique_key . "<br />";
echo "Mutliple Key: " . $property->multiple_key . "<br />";
echo "Numeric Field: " . $property->numeric . "<br />";
echo "BLOB: " . $property->blob . "<br />";
echo "Field Type: " . $property->type . "<br />";
echo "Unsigned: " . $property->unsigned . "<br />";
echo "Zero-filled: " . $property->zerofill . "<br /><br />";
}
mysql_close($con);
?>
被返回的对象的属性为:
•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
$con = mysql_connect("localhost", "hello", "321");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db("test_db",$con);
$sql = "SELECT * from 表名";
$result = mysql_query($sql,$con);
while ($property = mysql_fetch_field($result))
{
echo "Field name: " . $property->name . "<br />";
echo "Table name: " . $property->table . "<br />";
echo "Default value: " . $property->def . "<br />";
echo "Max length: " . $property->max_length . "<br />";
echo "Not NULL: " . $property->not_null . "<br />";
echo "Primary Key: " . $property->primary_key . "<br />";
echo "Unique Key: " . $property->unique_key . "<br />";
echo "Mutliple Key: " . $property->multiple_key . "<br />";
echo "Numeric Field: " . $property->numeric . "<br />";
echo "BLOB: " . $property->blob . "<br />";
echo "Field Type: " . $property->type . "<br />";
echo "Unsigned: " . $property->unsigned . "<br />";
echo "Zero-filled: " . $property->zerofill . "<br /><br />";
}
mysql_close($con);
?>
被返回的对象的属性为:
•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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE table_name='表名' and TABLE_SCHEMA='库名' ;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
DESC 表名
追问
只显示字段名。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询