查詢所有表的所有字段資訊

2021-08-24 21:06:26 字數 2348 閱讀 4332

select table_name from user_tables;

--查詢所有表的所有字段資訊

select a.table_name as 表名,

a.column_name as 列名 ,

a.data_type as 資料型別,

a.data_length as 長度,

a.nullable as 是否為空,

case when d.constraint_type = 'p' then 'y'

else 'n'end 是否為主鍵,

a.nullable as 為空,

a.column_id as 列序號,

b.comments as 備註

from user_tab_cols a inner join user_col_comments b on b.table_name=a.table_name

and b.column_name=a.column_name left outer join user_cons_columns c on a.table_name = c.table_name

and a.column_name = c.column_name left outer join user_constraints d on c.constraint_name = d.constraint_name

where a.table_name in (

select table_name from user_tables

group by a.table_name

--查詢單個表的所有字段資訊

select a.table_name as 表名,

a.column_name as 列名 ,

a.data_type as 資料型別,

a.data_length as 長度,

a.nullable as 是否為空,

case when d.constraint_type = 'p' then 'y'

else 'n'end 是否為主鍵,

a.column_id as 列序號,

b.comments as 備註

from user_tab_cols a inner join user_col_comments b on b.table_name=a.table_name

and b.column_name=a.column_name left outer join user_cons_columns c on a.table_name = c.table_name

and a.column_name = c.column_name left outer join user_constraints d on c.constraint_name = d.constraint_name

where a.table_name = 'code_dict'

--簡單查詢column資訊

select a.column_id,

a.column_name,

a.data_type,

a.data_length,

a.data_precision,

a.data_scale,

a.nullable,

a.data_default

from user_tab_columns a where table_name = 'code_dict'

order by column_id

select

a.column_name,a.data_type,a.data_length,a.data_precision,

a.data_scale,a.nullable,a.data_default,b.comments,d.constraint_type

from

user_tab_columns a,user_col_comments b ,user_cons_columns c ,user_constraints d

where

a.table_name = b.table_name

and a.column_name = b.column_name

and a.table_name = c.table_name and a.column_name = c.column_name

and c.table_name = d.table_name and c.constraint_name = d.constraint_name

and a.table_name = 'code_dict'

order by

column_id

select * from user_constraints d where d.table_name ='code_dict'

查詢所有資料庫中的所有表的所有欄位的資訊

查詢所有資料庫中的所有表的所有欄位的資訊 declare s varchar 8000 set s select s s select select name as dbname,a.name as tablename,b.name as colname,c.name as coltype,c.le...

Mssql 根據表名查詢所有字段資訊

select 表名 case when a.colorder 1 then d.name else end,表說明 case when a.colorder 1 then isnull f.value,else end,字段序號 a.colorder,欄位名 a.name,標識 case when ...

查詢表中所有字段

查詢某個表的欄位名 select column name from user tab columns where table name tablename 多行合併為一行,便於操作,可以用 wm concat select wm concat column name from user tab co...