常用的SQL彙總

2021-08-21 23:39:14 字數 856 閱讀 6354

/**mysql 取得資料庫名*/

show databases

/**根據庫名取得表名*/

select table_name from information_schema.`tables` where table_schema = 'dashboard';

/**根據表名取得欄位名*/

select column_name from information_schema.columns where table_name = 'da_dashboard_si_test';

/**根據表名取得表結構資訊*/

show full columns from da_dashboard_si_test

/**刪除表*/

drop table if exists 表名

/**新增字段*/

alter table 表名 add(score int not null);

/**移除字段*/

alter table 表名 drop column score;

/**變更字段*/

alter table 表名 change name score int not null;

/**並查詢*/

(select id from 表1 )union(select id from 表2);

/**建立普通索引*/

create index 索引名 on 表名 (字段);

/**建立唯一索引*/

create unique index 索引名 on 表名 (key欄位);

/**移除索引*/

drop index 索引名 on 表名;

Oracle 常用sql彙總

原文傳送門 select b.table name as 表名 c.comments as 表說明 b.column id as 字段序號 b.column name as 欄位名 concat concat concat b.data type,b.data length as 字段資料型別 b....

Mysql常用SQL彙總

今天的部落格主題 資料庫篇 mysql mysql常用sql彙總 目錄 字段合併去重 查詢結果追加自定義字串 查詢當天的資料 今天工作當中被同事問道資料庫需要兩個字段合併去重。簡單粗暴點,直接上code 表資料 需求 來吧三部曲 第一步 合併aa bb 字段 注意 這一步合併的時候根據欄位的分割符號...

mysql常用sql彙總

alter table student add zz int 11 default 0 comment 0是授權 1未授權 給表student 新增乙個zz的字段 預設是0 後面是注釋 alter table student drop column nick 給表student刪除nick欄位 1....