SQL 查询所有表名/指定表名、字段、类型、大小
SQL 查询所有表名/指定表名、字段、类型、大小
1、查询所有表名:
MS SQL
SELECT NAME FROM SYSOBJECTS WHERE TYPE='U'
MySQL
SELECT * FROM INFORMATION_SCHEMA.TABLES
Oracle
SELECT TABLE_NAME FROM USER_TABLES
ACCESS
SELECT NAME FROM MSYSOBJECTS WHERE TYPE=1 AND FLAGS=0
2、查询表的所有字段名:
MS SQL
SELECT NAME FROM SYSCOLUMNS WHERE ID=OBJECT_ID(' 表名' )
MySQL
SELECT * FROM INFORMATION_SCHEMA.TABLES
SELECT * FROM INFORMATION_SCHEMA.VIEWS
SELECT * FROM INFORMATION_SCHEMA.COLUMNS
3、查询所有表名/指定表名、字段、类型、大小
MS SQL
1、所有表
select t.name as tablename,c.name as columnname,ty.name as typename,
c.max_length as typelength
from sys.columns c inner join sys.tables t on t.object_id=c.object_id
inner join sys.types ty on ty.system_type_id=c.system_type_id
order by t.name,c.column_id
2、指定表
select b.name as tablename,a.name as columnname,c.name as typename,a.max_length as typelength
from sys.columns a inner join sys.tables b on b.object_id=a.object_id
inner join sys.types c on c.system_type_id=a.system_type_id
where b.name='表名'
order by b.name,a.column_id
创建时间:2021.05.11 更新时间:2021.06.07 2021.12.31
博客园 滔Roy https://www.cnblogs.com/guorongtao 希望内容对你有所帮助,谢谢!