Avatar of gvamsimba
gvamsimbaFlag for United Kingdom of Great Britain and Northern Ireland

asked on 

Exporting Data from one table to another in SQL Server 2005

HI,
      I need to export the data from one table to another in the same database in SQL Server 2005..Can anybody suggest which way is the best to do this . There are 3 million rows in my source table. Can i use the import
and export wizard ? Many Thanks
Microsoft SQL ServerMicrosoft SQL Server 2005

Avatar of undefined
Last Comment
tigin44
ASKER CERTIFIED SOLUTION
Avatar of PedroCGD
PedroCGD
Flag of Portugal image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Guy Hengel [angelIII / a3]
you could just do a plain insert
INSERT INTO your_dest_table ( col1, col2, col3...) 
 SELECT field1, field2, field3 ...
  FROM your_source_table
 WHERE ...

Open in new window

Avatar of tigin44
tigin44
Flag of Türkiye image

since your tables n the same database you dont need to use any export import wizard or anything else. Simply use a direct insert
INSERT INTO destinationTable (a, b, c, ...)
SELECT a,b,c, ....
FROM sourceTable
WHERE ...
Avatar of colinnaylor
colinnaylor
Flag of United Kingdom of Great Britain and Northern Ireland image

You could try this for speed after scripting out the source table:

sp_rename SourceTable, DestTable

Create table SourceTable(col, col .....)

Grant select, etc. on SourceTable to users

Avatar of gvamsimba
gvamsimba
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

This is my query for creating another table with different name..i have copied this create query from the source table and just changed the tablename..but it is giving error line 15 near (    Can anybody make the change to this query to make it right..


USE [MITS_Export]
GO
/****** Object:  Table [dbo].[tblCubeBroker]    Script Date: 01/29/2009 12:29:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tblCubeBroker](
      [datAuditDate] [datetime] NULL,
      [strAuditSource] [varchar](6) NULL,
      [strAuditUser] [varchar](6) NULL,
      [strCubeBrokerId] [varchar](10) NOT NULL,
      [strBrokerNo] [varchar](10) NULL,
      [strBrokerName] [varchar](50) NULL,
      [numBrokerGroup] [numeric](5, 0) NULL,
      [strGuaranteeBroker] [varchar](10) NULL,
      [strSoftwareHouse] [varchar](50) NULL,
      [strStatus] [varchar](5) NULL,
 CONSTRAINT [PK__tblCubeBroker__182C9B23] PRIMARY KEY CLUSTERED
(
      [strCubeBrokerId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
Avatar of Raja Jegan R
Raja Jegan R
Flag of India image

Your PK_ name needs to be changed.
It should be unique across the database.
Avatar of tigin44
tigin44
Flag of Türkiye image

you can use a structure like this too

SELECT * INTO destinationTable
FROM sourceTable

this syntax willl create the destination and copy the data from the source. But there will be no defaults, pk or fk relationship in the destination table.
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo