mysql操作目標表

2021-07-25 13:35:32 字數 703 閱讀 1491

mysql中you can't specify target table for update in from clause錯誤的意思是說,不能先select出同一表中的某些值,再update這個表(在同一語句中)。 例如下面這個sql:

update  market_data.curves  set id_calendar = 'bond_cn' where id_curve in

(select id_curve from market_data.curves where cd_curve_type = 'ir_bond'

and

id_curve not like 'ir_bond_cny_fix_ex_gov_spt') ;

將select出的結果再通過中間表select一遍,這樣就規避了錯誤。

update  market_data.curves  set id_calendar = 'bond_cn' where id_curve in

(select id_curve from

(select id_curve from market_data.curves where cd_curve_type = 'ir_bond'

and

id_curve not like 'ir_bond_cny_fix_ex_gov_spt') a);

mysql操作表 MySQL表的操作(一)

在建立表之前,首先要指明表在哪個資料庫中建立,也就是要指明命令所要操作的資料庫 用use語句選擇資料庫,一般格式 use 資料庫名 建立表的語法格式如下 例如選擇在linda資料庫中建立乙個use1表 use linda create table use1 id int,name varchar 2...

mysql 表的操作 mysql 表的操作

建立表 檢視表結構 修改表 刪除表 1.建立表 建立表之前選定資料庫 use testx create table table2 屬性名 資料型別 約束 屬性名 資料型別 約束 約束 primary key 該屬性 欄位設為此表主鍵 foreign key 該屬性 欄位為該表外來鍵,即另乙個表的主鍵...

mysql表操作約束 MySQL操作表的約束

完整性 指資料庫的準確性和一致性。約束 是在表中定義的用於維護資料庫完整性的一些規則。主鍵 給某乙個欄位來唯一標識所有記錄,值是唯一的,非空的 外來鍵 多個表之間參照的完整性。一 設定非空約束 use教學管理資料庫 show tables create table專業表 專業編號char 3 not...