mysql表是否存在,mysql 判斷表是否存在,存在並刪除

時間 2021-10-14 22:24:14

1樓:stone李想

一般都是在建立時新增一個判斷條件 if  (not) exists,僅是為查詢,也可執行sql。

select table_name from information_schema.tables where table_schema='目標資料庫' and  table_name='表名'。

select table_name from information_schema.tables where  table_name='表名'。

2樓:匿名使用者

有四種方式進行判斷:

show tables like '%tb_bp_d_case%';

2.select table_name from information_schema.tables where table_schema='dbname' and table_name='tablename' ;

3. 如果表不存在就建立這個表,那麼可以直接用create table if not exists tablename

這樣的指令來建立,不需要先去查詢表是否存在。

4. 從模板表建立表:

create table if not exists like old_table_name;

mysql 判斷表是否存在,存在並刪除

3樓:

show   tables   like   '%tb_bp_d_case%';

2. select `table_name` from `information_schema`.`tables` where `table_schema`='dbname' and `table_name`='tablename' ;

3. 如果表不存在就建立這個表,那麼可以直接用 create table if not exists tablename 這樣的指令來建立,不需要先去查詢表是否存在。

4. 從模板表建立表:create table if not exists like old_table_name;

drop table if exists tbl_name;

mysql判斷表是否存在某個列

4樓:愛刷

最佳答案: 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 有時會更改列型別。

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

5樓:匿名使用者

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'

6樓:匿名使用者

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

python怎麼判斷mysql中是否存在某個表

7樓:

下面**示例中的exist_of_table(table_name)是個人自寫的一個方法:

我在mysql資料庫中的scraping庫中建立有city和country表,所以結果返回的是:

即city表已經存在。

僅供參考!

mysql選擇表查詢的問題,當表A中存在記錄則輸出A表資料,否則輸出B表資料

select id name,other from select nvl a.id,b.id id nvl a.name,b.name name nvl a.other,b.other other from a full outer join b on a.name b.name where nam...

mysql如何統計表大小,mysql中如何統計一個資料庫中每張表的行數

表統計資訊是資料庫基於成本的優化器最重要的參考資訊 統計資訊不準確,優化器可能給出不夠優化的執行計劃或者是錯誤的執行計劃。對統計資訊的計算分為非持久化統計資訊 實時計算 與持久化統計資訊。非持久化統計資訊 統計資訊沒有儲存在磁碟上,而是頻繁的實時計算統計資訊 每次對錶的訪問都會重新計算其統計資訊 假...

mysql資料庫兩個表的比較,mysql資料庫兩個表的比較

select id,q3 from select id,q3 from select m1.id,nvl m1.q1,0 nvl m2.q2,0 q3 from select id,sum qian q1 from 30money group by id m1 left join select id...