怎麼判斷資料庫表中是否存在某條資料,用的MYSQL

2021-03-03 23:20:25 字數 3337 閱讀 1216

1樓:匿名使用者

select count(*) from 表名 where 條件

返回符合條件的資料條數

2樓:夢裡尋你我他

select count(*) as n from table where 字段='abc'

3樓:匿名使用者

select count(*) from 《基本表名》;

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

4樓:匿名使用者

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'

5樓:匿名使用者

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 = '你指定的列名稱'

如何判斷資料庫中是否存在某個資料?

6樓:匿名使用者

判斷方法如下

一、select 字段

列表 from 資料表

例:1、select id,g**c,add,tel from haf (* 表示資料表中所有字段)

2、select 單價,數量,單價*數量 as 合計金額 from haf (as 設定欄位的別名)

二、select ... from ... where 篩選條件式

例 篩選條件式:

1、字串資料: select * from 成績單 where 姓名='李明'

2、萬用字元: select * from 成績單 where 姓名 like '李%' select * from 成績單 where 姓名 like '%李%' select * from 成績單 where 姓名 like '%李_'

3、特殊的條件式:1.= / > / < / <> / >= / <=

2.and邏輯與 or邏輯或 not邏輯非

3.where 欄位名稱 in(值一,值二)

4.where 欄位名稱 is null / where 欄位名稱 is not null

mysql 怎麼判斷乙個表中的某一列有沒有某個值

7樓:匿名使用者

1、mysql中建立測試表,create table test_user(id int, name varchar(20));

2、插入測試資料,

insert into test_user values(1001,'jack');

insert into test_user values(1002,'lucy');

insert into test_user values(1003,'mike');

insert into test_user values(1004,'john');

insert into test_user values(1005,'may');

3、檢視表中所有

專資料,select * from test_user

4、編寫屬sql,查詢name列是否有jack名,

select * from test_user t where name = 'jack'

8樓:sweet丶奈何

可以用 select count(*) from table where username ='dpstill';

查詢bai的結果du=0 就不存

zhi在dao >0 就存在

如果要用

版其他結果返回的話,可以用權下面的

select case when count(*)>0 then '存在' when count(*)=0 then '不存在' end from table where username ='dpstill'

9樓:匿名使用者

直接select where那個值不行麼?再看看返回的資料集是否為空。

10樓:

select * from table where 查詢列名='你的值'?是不是這個意思

11樓:花臂華盛頓

mysql_connect('localhost', 'root', '11');

mysql_select_db('庫名

zhidao');

$field = mysql_query('describe 表名專欄位

屬名');

$field = mysql_fetch_array($field);

if($field[0])else

在sql資料庫中怎麼判斷某張表是否已經存在了

if exists select from sysobjects where name bbsusers drop table bbsusers bbsusers 是要 bai查詢du的zhi 表dao sysobjects 是系統內錶容 應為bai if exists select from sy...

asp判斷資料庫是否有資料,asp判斷資料庫是否有資料

資料庫連線語句我就不寫了。set rs server.createobject adodb.recordset sql select beizhu from service where 條件 rs.open sql,conn,1,1 if rs beizhu thenresponse.write 0...

oracle資料庫中資料庫和表空間是等同的嗎

不等同。簡單的說,資料庫是乙個整體,乙個資料庫下可保護多個使用者 多個表 多個儲存過程 多個job 多個檢視等。而表空間可以認為是資料實體檔案的分類,比如有使用者表空間 系統表空間 索引表空間等,乙個表空間可以保護多個實體檔案。可以設定表空間的儲存大小,但實際使用多少由已存在的資料來決定。比如設定使...