如何将table复制到另一个table?
How to copy table to another table?
我有一个 table 有 1 000 000 条记录:
CREATE TABLE [dbo].[x2](
[session_id] [uniqueidentifier] NOT NULL,
[node_id] [uniqueidentifier] NOT NULL,
[id] [int] IDENTITY(1,1) NOT NULL,
CONSTRAINT [PK_x2] PRIMARY KEY CLUSTERED
(
[id] ASC
));
我需要替换字段
[id] [int] IDENTITY(1,1)
与
[id] [bigint] IDENTITY(1,1)
但是所有数据(包括 id 值)都应该复制到新的 table 并且 id 应该是 IDENTITY 而不是 bigint。
我创建了新的 table
CREATE TABLE [dbo].[x2_new](
[session_id] [uniqueidentifier] NOT NULL,
[node_id] [uniqueidentifier] NOT NULL,
[id] [bigint] IDENTITY(1,1) NOT NULL,
CONSTRAINT [PK_x2_new] PRIMARY KEY CLUSTERED
(
[id] ASC
));
并尝试复制数据:
insert into x2_new(session_id,node_id,id)
select session_id,node_id,id from x2;
但是很慢。如何更快地将数据复制到新 table?
如果您的两个表都在同一个数据库中,为什么不立即使用导入数据任务功能、select 列和 运行 SSIS 包。
在那种情况下..你需要在你的目的地做一个'identity_insert OFF'并用你的脚本插入..也尝试设置NoLock..但这是一次性activity还是重复一个?
我有一个 table 有 1 000 000 条记录:
CREATE TABLE [dbo].[x2](
[session_id] [uniqueidentifier] NOT NULL,
[node_id] [uniqueidentifier] NOT NULL,
[id] [int] IDENTITY(1,1) NOT NULL,
CONSTRAINT [PK_x2] PRIMARY KEY CLUSTERED
(
[id] ASC
));
我需要替换字段
[id] [int] IDENTITY(1,1)
与
[id] [bigint] IDENTITY(1,1)
但是所有数据(包括 id 值)都应该复制到新的 table 并且 id 应该是 IDENTITY 而不是 bigint。
我创建了新的 table
CREATE TABLE [dbo].[x2_new](
[session_id] [uniqueidentifier] NOT NULL,
[node_id] [uniqueidentifier] NOT NULL,
[id] [bigint] IDENTITY(1,1) NOT NULL,
CONSTRAINT [PK_x2_new] PRIMARY KEY CLUSTERED
(
[id] ASC
));
并尝试复制数据:
insert into x2_new(session_id,node_id,id)
select session_id,node_id,id from x2;
但是很慢。如何更快地将数据复制到新 table?
如果您的两个表都在同一个数据库中,为什么不立即使用导入数据任务功能、select 列和 运行 SSIS 包。
在那种情况下..你需要在你的目的地做一个'identity_insert OFF'并用你的脚本插入..也尝试设置NoLock..但这是一次性activity还是重复一个?