如何使用sql語句查詢資料庫的表中字段數目

2021-10-06 17:18:13 字數 831 閱讀 5571

1、oracle:

select count(*

) from user_tab_cols where table_name=

'表名'

;

注意:表名中的英文本母大寫

2、mysql:

select count(*

) from information_schema.columns where table_name=

'表名'

;

注意:表名中的英文本母大小寫均可,如果不在指定資料庫中查詢,可能會出現字段數目大於真實情況,但是都是在指定的資料庫中查詢的啊,暫時還沒有遇到這樣的情況,如果你遇到了,可以使用下面的sql語句:

select count(*

) from information_schema.columns where table_schema =

'資料庫名' and table_name=

'表名'

;

3、sqlserver:

select count(*

) from syscolumns where id =

object_id

('表名'

);

注意:表名中的英文本母大小寫均可

解釋:syscolumns中儲存著當前資料庫中所有表的所有字段資訊,id代表該欄位所屬的表的id,object_id(『表名』)返回表的id

資料庫SQL語句查詢

新手小白菜一枚,求知 查詢所有同學的學號 姓名 選課數 總成績 select t1.stuid,t1.stuname,count t2.courseid sum score from tblstudent t1,tblscore t2 where t1.stuid t2.stuid group by...

資料庫SQL語句使用

擷取字段 string sgtoday,6,2 引數1 要擷取的字段,引數2 從第幾位擷取,引數3 擷取長度。例如 擷取folder no欄位從第一位開始的長度和fonds no相同的字段 select from folder description kj where substring folde...

sql 資料庫查詢語句總結

1,將表中的某一列 costtime 中的post days 全部替換成tage update sys delivery set costtime replace costtime,post days tage 2.將有乙個表的資料更新相對應的字段。select from sys protectio...