使用show tables语句就可以显示当前数据库中所有的表。
查找所有表的具体语句的例子如下:
1、select table_name
from information_schematables
where table_schema='当前数据库'
2、select name from SysObjects where type='u'
扩展资料:
查询指定数据库中指定表的所有字段名,例如:column_name
select column_name from information_schemacolumns
where table_schema='csdb' and table_name='users'
查询的其他语句:
select from all_col_comments –查询所有用户的表的列名和注释。
select from user_col_comments – 查询本用户的表的列名和注释 。
select from all_tab_columns –查询所有用户的表的列名等信息(详细但是没有备注)。
select from user_tab_columns –查询本用户的表的列名等信息(详细但是没有备注)。
参考资料:
你现在只需要查询所有表中的姓名,那SQL语句就应该这样写
SELECT 姓名 FROM 表名 //这样即可Oracle 例子:
SQL> SELECT
2 column_name
3 FROM
4 all_tab_columns
5 WHERE
6 table_name = 'SALE_REPORT';
COLUMN_NAME
------------------------------------
SALE_DATE
SALE_ITEM
SALE_MONEY
SQL Server 例子:
SELECT
colname AS 列名,
typname as 数据类型,
colmax_length AS 占用字节数,
colprecision AS 数字长度,
colscale AS 小数位数,
colis_nullable AS 是否允许非空,
colis_identity AS 是否自增,
case when exists
( SELECT 1
FROM
sysindexes idx
join sysindex_columns idxCol
on (idxobject_id = idxColobject_id)
WHERE
idxobject_id = colobject_id
AND idxColindex_column_id = colcolumn_id
AND idxis_primary_key = 1
) THEN 1 ELSE 0 END AS 是否是主键
FROM
syscolumns col left join systypes typ on (colsystem_type_id = typsystem_type_id AND coluser_type_id = typuser_type_id)
WHERE
colobject_id =
(SELECT object_id FROM systables WHERE name = 'test_table')
MySQL 例子:
mysql> SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT
-> FROM
-> INFORMATION_SCHEMACOLUMNS
-> WHERE
-> table_name = 'test_main'
-> AND table_schema = 'test'
-> //
+-------------+-----------+-------------+----------------+
| COLUMN_NAME | DATA_TYPE | IS_NULLABLE | COLUMN_DEFAULT |
+-------------+-----------+-------------+----------------+
| id | int | NO | 0 |
| value | varchar | YES | NULL |
+-------------+-----------+-------------+----------------+
2 rows in set (000 sec)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)