查询数据库的数据库名和表名(MySQL、MSSQL、ORACLE) |
您所在的位置:网站首页 › 查看数据库的表格命令 › 查询数据库的数据库名和表名(MySQL、MSSQL、ORACLE) |
MySQL中查询所有数据库名和表名
1.查询所有数据库 show databases; 2.查询指定数据库中所有表名 select table_name from information_schema.tables where table_schema='database_name' and table_type='base table'; 3.查询指定表中的所有字段名 select column_name from information_schema.columns where table_schema='database_name' and table_name='table_name'; 4.查询指定表中的所有字段名和字段类型 select column_name,data_type from information_schema.columns where table_schema='database_name' and table_name='table_name'; SQLServer中查询所有数据库名和表名 1.查询所有数据库 select * from sysdatabases; 2.查询当前数据库中所有表名 select * from sysobjects where xtype='U'; xtype='U':表示所有用户表,xtype='S':表示所有系统表。 3.查询指定表中的所有字段名 select name from syscolumns where id=Object_Id('table_name'); 4.查询指定表中的所有字段名和字段类型 select sc.name,st.name from syscolumns sc,systypes st where sc.xtype=st.xtype and sc.id in(select id from sysobjects where xtype='U' and name='table_name'); 5.表结构查询 1) select * from syscolumns where id=object_id('表名')2) SELECT CASE WHEN col.colorder = 1 THEN obj.name ELSE '' END AS 表名, col.colorder AS 序号 , col.name AS 列名 , ISNULL(ep.[value], '') AS 列说明 , t.name AS 数据类型 , col.length AS 长度 , ISNULL(COLUMNPROPERTY(col.id, col.name, 'Scale'), 0) AS 小数位数 , CASE WHEN COLUMNPROPERTY(col.id, col.name, 'IsIdentity') = 1 THEN '√' ELSE '' END AS 标识 , CASE WHEN EXISTS ( SELECT 1 FROM dbo.sysindexes si INNER JOIN dbo.sysindexkeys sik ON si.id = sik.id AND si.indid = sik.indid INNER JOIN dbo.syscolumns sc ON sc.id = sik.id AND sc.colid = sik.colid INNER JOIN dbo.sysobjects so ON so.name = si.name AND so.xtype = 'PK' WHERE sc.id = col.id AND sc.colid = col.colid ) THEN '√' ELSE '' END AS 主键 , CASE WHEN col.isnullable = 1 THEN '√' ELSE '' END AS 允许空 , ISNULL(comm.text, '') AS 默认值 FROM dbo.syscolumns col LEFT JOIN dbo.systypes t ON col.xtype = t.xusertype inner JOIN dbo.sysobjects obj ON col.id = obj.id AND obj.xtype = 'U' AND obj.status >= 0 LEFT JOIN dbo.syscomments comm ON col.cdefault = comm.id LEFT JOIN sys.extended_properties ep ON col.id = ep.major_id AND col.colid = ep.minor_id AND ep.name = 'MS_Description' LEFT JOIN sys.extended_properties epTwo ON obj.id = epTwo.major_id AND epTwo.minor_id = 0 AND epTwo.name = 'MS_Description' WHERE obj.name = '表名' ORDER BY col.colorder ;Oracle中查询所有数据库名和表名 1.查询所有数据库 由于Oralce没有库名,只有表空间,所以Oracle没有提供数据库名称查询支持,只提供了表空间名称查询。 select * from v$tablespace;--查询表空间(需要一定权限) 2.查询当前数据库中所有表名 select * from user_tables; 3.查询指定表中的所有字段名 select column_name from user_tab_columns where table_name = 'table_name';--表名要全大写 4.查询指定表中的所有字段名和字段类型 select column_name, data_type from user_tab_columns where table_name = 'table_name';--表名要全大写
文章参考:https://www.cnblogs.com/ParanoiaApe/p/9005266.html |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |