【请问】从两个相关表update其中一个表的两个字段,效率很低,两个小时了,还没结束,为什么?(各有数据50w/10w)
1.SQL语句如下:
---------------------------------------------------------------
update new_Table a
set (a.AreaId,a.TypeId) = (select b.AreaId,b.TypeId
from DataTable b
where substr(trim(a.Col),1,length(trim(b.Num))) = trim(b.Col));
2.表结构如下:
---------------------------------------------------------------
new_Table 有50w左右数据,DataTable 有近10w数据,
new_Table.Col 前面的几位值与 DataTable.Num关联(相等).
3.表结构如下:
---------------------------------------------------------------
-- ============================================================
-- Table: new_Table
-- ============================================================
create table new_Table
(
Col CHAR(15) not null,--数据位数>9
AreaId CHAR(6) null ,
CardTypeId CHAR(6) not null,
constraint PK_NEW_TABLE primary key (Col)
)
/
-- ============================================================
-- Table: DataTable
-- ============================================================
create table DataTable
(
Num CHAR(15) not null,--数据位数固定为3/4/7
AreaId CHAR(6) null ,
CardTypeId CHAR(6) not null,
constraint PK_DATATABLE primary key (Num)
)
/
相关推荐
Mysql 根据一个表数据更新另一个表的某些字段(sql语句)
下面一段代码给大家介绍Mysql 根据一个表数据更新另一个表的某些字段,具体代码如下所示: DROP TABLE IF EXISTS T_U_TEMPLATE; -- 模版表 CREATE TABLE T_U_TEMPLATE ( ID INT NOT NULL AUTO_INCREMENT comment '模版表ID', TEMPLATE_CODE VARCHAR(50) BINARY comment '模版编码', TEMPLATE_NAME VARCHAR(300) BINARY comment '模版名称', CREATE_TIME datetime D
SQL Server 触发器 表的特定字段更新时,触发Update触发器
代码如下: create trigger TR_MasterTable_Update on MasterTable after update as if update ([Type])–当Type字段被更新时,才会触发此触发器 insert into MasterLogTable select Id ,(Case [Type] when 1 then ‘Type1’ when 2 then ‘Type2’ when 3 then ‘Type3’ when 4 then ‘Type4’ else ‘TypeDefault’ end) ,Name from inserted go 另外再补充一句
MySQL 从一张表update字段到另外一张表中
使用MySQL 4.0版或更高更新您可以通过加入两个或多个表一起一表;通过加入两个表连同您可以更新一个表的记录在相关领域的总部设在另一个表。
mysql把一个表某个字段的内容复制到另一张表的某个字段的SQL语句写法
需求:把一个表某个字段内容复制到另一张表的某个字段。 实现sql语句1: 代码如下:UPDATE file_manager_folder f1LEFT OUTER JOIN file_manager_folder f2 ON f1.name = f2.name AND f2.parentId = 54SET f1.parentId = 54 WHERE f2.name IS NULL AND f1.id IN (1,2,3); 实现sql语句2: 代码如下:update B set extra = A.extra from A join B on (A.id = B.id); 实现sq
ORACLE多表关联的update语句
在某个业务受理子系统BSS中, --客户资料表 create table customers ( customer_id number(8) not null, -- 客户标示 city_name varchar2(10) not null, -- 所在城市 customer_type char(2) not null, -- 客户类型 ... ) create unique index PK_customers on customers (customer_id) 由于某些原因,客户所在城市这个信息并不什么准确,但是在 客户服务部的CRM子系统中,通过主动服务获取了部分客户20%的所在 城市等准确信息,于是你将该部分信息提取至一张临时表中: create table tmp_cust_city ( customer_id number(8) not null, citye_name varchar2(10) not null, customer_type char(2) not null )


基础和管理
