当前位置:数据库 > SQLServer >>

SQL查询表名、列名、列属性

SQL查询表名、列名、列属性
 
Oracle: 
1.查询表名: 
Sql代码  
select table_name,tablespace_name,temporary from user_tables  //在所有非管理员创建的表中查询  
select table_name,tablespace_name,temporary from dba_tables  //在所有管理员创建的表中查询  
select table_name,tablespace_name,temporary from all_tables  //在所有表中查询  
select table_name,tablespace_name,temporary from all_tables where table_name='表名' //在所有表中查询指定表  
select table_name,tablespace_name,temporary from all_tables where lespace_name='表空间名' //在所有表中查询属性指定表空间的表        
  其中:table_name:表名(varchar2(30));  
  tablespace_name:存储表名的表空间(varchar2(30));  
  temporary:能无法 为暂时表(varchar2(1))。  
  eg: select table_name,tablespace_name,temporary from user_tables where table_name='TEST_TEMP';  

  结果: 
  -------------------------------------------------------------------------------- 
  table_name tablespace_name temporary 
  TEST_TEMP SDMP N 
  -------------------------------------------------------------------------------- 
  注:表名变量值必须大写。 
  2.查询表列名: 
‍
Sql代码  
SELECT COLUMN_NAME FROM USER_TAB_COLUMNS WHERE TABLE_NAME = '表名' ORDER BY COLUMN_ID  
SELECT COLUMN_NAME FROM DBA_TAB_COLUMNS WHERE TABLE_NAME = '表名' ORDER BY COLUMN_ID  
‍SELECT COLUMN_NAME FROM ALL_TAB_COLUMNS WHERE TABLE_NAME = '表名' ORDER BY COLUMN_ID  
select column_name,data_type ,data_length,data_precision,data_scale from user_tab_columns where table_name='表名';  
  其中:column_name:列名(varchar2(30));  
  data_type:列的数据类型(varchar2(106));  
  data_length:列的长度(number);  
  eg:select column_name,data_type ,data_length,data_precision,data_scale from user_tab_columns where table_name='TEST_TEMP';  

       结果: 
       column_name data_type data_length data_precision data_scale 

  ID NUMBER 22 0 
  NAME NVARCHAR2 20 
  SEX CHAR 1 
  GRADE NVARCHAR2 10 
  -------------------------------------------------------------------------------- 
  注:表名变量值必须大写。 

 

  另外,也可以 议决 all_tab_columns来获取有关表的数据。 
  eg:select * from all_tab_columns where table_name='TEST_TEMP';
 
Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,