mysql查詢表中是否有某個欄位

2021-05-25 23:50:59 字數 4695 閱讀 6392

1樓:匿名使用者

information_schema.columns這表bai儲存了所

du有欄位資訊

zhiselect

count(*)

from

information_schema. columnswhere

table_schema = 'world'

and table_name = 'city'

and column_name = 'id'

查詢條件dao可以自

回己去修改答

mysql中如何查詢指定的表中是否存在某個列?

2樓:匿名使用者

1、建立資料庫表,create table test_users(user_id bigint, user_name varchar(100));

2、檢視系統檢視tables,在系統檢視中可以查到剛建的資料表,select * from information_schema.tables t where table_name = 'test_users',

3、檢視系統檢視columns,在系統檢視中可以查到該表所有的欄位,select * from information_schema.columns t where table_name = 'test_users',

4、查詢表中不存在的欄位,執行無返回結果,

select * from information_schema.columns t

where table_name = 'test_users'

and column_name = 'user_id2'

3樓:匿名使用者

mysql> select column_name, data_type, is_nullable, column_default

-> from

->   information_schema.columns

-> where

->   table_name = 'test_main'

->   and table_schema = 'test'

-> //

| column_name | data_type | is_nullable | column_default |

| id          | int       | no          | 0              |

| value       | varchar   | yes         | null           |

2 rows in set (0.00 sec)

通過上面這個 sql 語句, 能明白麼?

就是查詢 information_schema.columns

條件是  表名稱是  test_main,  資料庫是  test  的所有列的資訊。

如果你要查詢某些是否存在, 那麼再多加一個條件   and  column_name  =  '你指定的列名稱'

mysql 怎麼查詢資料庫是否有某個欄位

4樓:哈皮的小逗比

查詢資料

來庫中所有表源

名稱的語句

select table_name, table_type, engine

from information_schema.tableswhere table_schema = '資料庫名稱'

order by table_name desc;

查詢mysql資料庫中所有包含特定名字的欄位所在的表select * from information_schema.columns

where column_name like '%placement%';

5樓:匿名使用者

檢視資料庫表的所有欄位

desc 表名;

查詢資料庫表中是否存在某一欄位

6樓:匿名使用者

mysql資料庫下的sql語句

select table_schema,table_name,column_name

from information_schema.columns awhere a.column_name = 'update_time' order by table_schema,table_name

這是查詢到存在的,不存在的換成不等號,只要專庫名錶名可以

屬加group by table_schema,table_name

7樓:殺·破狼

select name from sysobjects where id in (select id from syscolumns where name='你要查詢的欄位名

bai')

這樣不du單可以zhi確定這個dao欄位是否存專在。並且可以得出擁有這個欄位的所有表名~屬~~~

8樓:

select b.name as 表名, a.name as 欄位名

from sys.columns a

where a.name = '你要查的欄位名稱'

mysql判斷表是否存在某個列

9樓:愛刷

最佳答案: mysql使用describe命令判斷欄位是否存在 工作時需要取得mysql中一個表的欄位是否存在 於是就使用describe命令來判斷 mysql_connect('localhost', 'root', 'root'); mysql_select_db('demo'); $test = mysql_query('describe cdb_posts first'); $test = mysql_fetch_array($test); $test[0]返回的是該欄位的名 工作時需要取得mysql中一個表的欄位是否存在 於是就使用describe命令來判斷 mysql_connect('localhost', 'root', 'root'); mysql_select_db('demo'); $test = mysql_query('describe cdb_posts first'); $test = mysql_fetch_array($test); $test[0]返回的是該欄位的名稱,比如我要查詢first欄位,返回的就是first 如果此欄位不存在返回的就是null,通過這樣可以判斷一個欄位是否存在 附加資料: describe命令

一、describe命令用於檢視特定表的詳細設計資訊,例如為了檢視guestbook表的設計資訊,可用: describe guestbook

二、可通過」show comnus」來檢視資料庫中表的列名,有兩種使用方式: show columns form 表名 from 資料庫名 或者: show columns from 資料庫名.

表名三、用describe命令查詢具體列的資訊 describe guestbook id 就是查詢guestbook中id欄位的列資訊 tbl_name [col_name | wild] describe 是 show columns from 的縮寫。describe 提供有關一個表的列資訊。col_name 可以是一個列名或是一個包含 sql 萬用字元字元 「%」 和「_」 的字串。

沒有必要用引號包圍字串。 如果列型別不同於你所期望的基於一個 create table 語句建立的列,注意 mysql 有時會更改列型別。

sql 如何判斷表中的某個欄位是否有某個值 15

10樓:匿名使用者

select  case when aaaa like'%1%' then '1' else '0' end

from table

11樓:匿名使用者

方法一:

select replace(欄位名bai,'e','考察')replace意思:如果取得du欄位值是e則替換為zhi"考察"

方法dao二

select decode(columnname,值1,翻譯內值1,值2,翻譯值2,...值n,翻譯值n,預設容值

12樓:我是你謙

charindex sql 內建函式,用法如下:

select top 5 substring(contactname,charindex(' ',contactname)+1,len(contactname)) as [last name] from customers charindex函式找到first name和last name之間的空格,所以substring函式可以分開contactname列,這樣就只有回last name被選出。答在charindex函式返回的整數上加1,這樣last name不是從空格開始。

13樓:意由不得你

select count(1) from table where aaaa=1

if(sql>0)else

14樓:kevin菸圈

是包含1還是等於1

包含1 和話

$sql = "select * from table where aaaa like '%1%'";

如果查到輸出

專1 否則屬輸出0

包含等於 1和話

$sql = "select * from table where aaaa = '1' ";

如果查到輸出1 否則輸出0

在mysql資料庫中如何讓某個欄位有重複的只取一條

保留 bai相du 同zhia值的 dao最小 專屬id行 select from table a a where not exists select 1 from table a bwhere b.a a.a and b.id a.id select top 1 id,name,age from ...

怎麼查詢表中某個欄位相同值的記錄數大於1的記錄

這應該就是彙總查詢吧,不知道你用的什麼資料庫,查詢方法會稍有差異。通常就是group by,在簡單的access庫裡面,直接可以用sum as,條件裡面設為大於1 怎麼查詢一個表中 某個欄位相同值的 記錄數大於1的 記錄?表結構呢?select from tab where 商品編碼 in sele...

MySQL判斷表是否存在某個列,mySQL中如何查詢指定的表中是否存在某個列

最佳答案 mysql使用describe命令判斷欄位是否存在 工作時需要取得mysql中一個表的欄位是否存在 於是就使用describe命令來判斷 mysql connect localhost root root mysql select db demo test mysql query desc...