基礎SQL整理

2021-08-19 10:27:44 字數 755 閱讀 4850

一. mysql 表新增字段

1.alter table people add column name varchar(100) default null comment '姓名'  

修改表 people  增加字段 name    長度100  預設為null   備註:姓名

二. mysql 將一張表的結果插入到另一張表中(你沒看錯,中間不用什麼連線,看起來就像是兩條不相關的sql)

1.insert into wallet_log (id,user_id,total_fee,status,create_time)

select id,mobile,score,'1',now() from t_account

2.insert into sys_re_user_role (id,user_id,role_id,create_time)

select sysid,id,roleid, ifnull(lastuptime,createtime) from t_user2

三. mysql 多表關聯更新

1.update sys_user s,t_user t set s.limit_time = t.lastuptime where s.id = t.id;

2.update sys_user u1 ,sys_user u2 set u1.recommend_time=u2.create_time 

where u1.recommend_id=u2.id and u1.recommend_id is not null;

SQL基礎整理

用於訪問和處理資料庫的標準的計算機語言,結構性查詢語言 structured query language 可以訪問和處理資料庫,一種 ansi american national standards institute 美國國家標準化組織 標準的計算機語言。mysql 資料型別 在 mysql 中...

常用基礎sql整理

show databases 顯示所有資料庫 create database abc 建立資料庫abc useabc 使用資料庫abc create table aa id int name varchar 30 age int 建立表aa id,name,age desc aa 顯示表aa中的欄位...

sql注入整理

推薦 sql注入攻防入門 sql注入 工具 scott guthrie 就提到了5點來防範 1 在構造動態sql語句時,一定要使用類安全 type safe 的引數加碼機制。也就是引數化 2 在部署你的應用前,始終要做安全審評 security review 3 千萬別把敏感性資料在資料庫裡以明文存...