  
表名，字段名，字段类型，字段长度 
select o.name as tbna, c.name as colna, t.name as typena, c.length as lenna 
from 
syscolumns c inner join 
sysobjects o on c.id = o.id and o.xtype = 'u' inner join 
systypes t on c.xtype = t.xtype 
如果后面加上where，就可以得到指定表的信息。 
where o.name = '指定表名'

Oracle---------------------------
SELECT  table_name,COLUMN_NAME,DATA_TYPE,DATA_LENGTH   FROM   user_TAB_COLUMNS 

select * from user_tables; //查看当前用户的所有表的信息
select * from all_tables;    //查看当前数据库中所有表信息

select * from user_tab_columns; //查看当前用户所有表的字段等信息
select * from all_tab_columns;  //查看所有表的字段名等信息

----------------------------------------

SELECT     COLUMN_NAME,DATA_TYPE,DATA_LENGTH       //字段名稱，數據類型，長度   
  FROM     
    (SELECT   to_char(rownum)   num   ,COLUMN_NAME,DATA_TYPE,DATA_LENGTH   
      FROM   ALL_TAB_COLUMNS   
      WHERE   table_name   =   'BUILDING')   
  where   num   =   2   
  NOTE:表名字母要大寫   


 
--查询当前数据库所有表的主键
SELECT TABLE_NAME,COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE TABLE_NAME<> 'sysdiagrams' and CONSTRAINT_Name like 'PK_%'

--判断Table是否存在自增列(Identity column),并查出自增列相关数据：
declare @Table_name varchar(60)
set @Table_name = 'Product';
Select so.name Table_name, --表名字
sc.name Iden_Column_name, --自增字段名字
ident_current(so.name) curr_value, --自增字段当前值
ident_incr(so.name) incr_value, --自增字段增长值
ident_seed(so.name) seed_value --自增字段种子值
from sysobjects so 
Inner Join syscolumns sc
on so.id = sc.id
and columnproperty(sc.id, sc.name, 'IsIdentity') = 1
Where upper(so.name) = upper(@Table_name)

---查询外键表及引用咧
 select t1.ftableName,t1.name,t2.rtableName,t2.name
from
(select OBJECT_NAME(f.fkeyid) as ftableName, col.name, f.constid as temp
 from syscolumns col,sysforeignkeys f
 where f.fkeyid=col.id
 and f.fkey=col.colid
 and f.constid in
 ( select distinct(id) 
   from sysobjects
   where OBJECT_NAME(parent_obj)='SalesHistory'
   and xtype='F'
  )
 ) as t1 ,
(select OBJECT_NAME(f.rkeyid) as rtableName,col.name, f.constid as temp
 from syscolumns col,sysforeignkeys f
 where f.rkeyid=col.id
 and f.rkey=col.colid
 and f.constid in
 ( select distinct(id)
   from sysobjects
   where OBJECT_NAME(parent_obj)='SalesHistory'
   and xtype='F'
 )
) as t2