Author Topic: Import Excel data into SQL Server using copy and paste  (Read 4243 times)

Budi Santoso

  • Dealer OtomaX
  • Sr. Member
  • ****
  • Posts: 1,996
  • Budi Santoso
Import Excel data into SQL Server using copy and paste
« on: March 15, 2012, 07:10:08 PM »
Import Excel data into SQL Server using copy and paste


Problem
Loading data from SQL Server to Excel is a common practice in many automated and ad-hoc processes completed by DBAs on a daily basis.  Traditionally loading data from Excel to SQL Server has been completed by DTS, SSIS, BCP, OPENROWSET, Import\Export Wizard, etc.  Unfortunately, for a simple ad-hoc process this can be a time consuming task with a fair amount of clicks and\or coding.  With all of the new features with in SQL Server 2005, are any new tricks available to streamline the Excel to SQL Server loading process?

Solution
Yes - SQL Server 2005 Management Studio provides the ability to copy and paste columns directly from Excel to SQL Server when the table and column names match up.  Let's walk through a simple example.  Assume you have a database called 'Test' with a table called 'MyTable' consisting of two columns (MyID, MyDesc).  In addition, you have an Excel worksheet where you want to load data directly from Excel to SQL Server.  Let's walk through setting up and testing that scenario.

Step 1 - Create the Database and Table
CREATE DATABASE Test
GO
CREATE TABLE [dbo].[MyTable](
      [MyID] [int] NOT NULL,
      [MyDesc] [varchar](100) NOT NULL)
 

Step 2 - Open the Excel worksheet, select data only and copy the data 'Ctrl +C'



Step 3 - Open SQL Server 2005 Management Studio and navigate to the table



Step 4 - Right click on dbo.MyTable, choose 'Open Table' then left click on below area



Step 5 - The area below will be highlighted, then right click and choose 'Paste'



Step 6 - Validate the data will be inserted into the table



Sumber : http://www.mssqltips.com/sqlservertip/1430/import-excel-data-into-sql-server-using-copy-and-paste/
SAFANA Corporation
IT Solution - Online Payment - General Payment


Jam Kerja Fix 07:00 - 22:00 Setiap Hari, Kecuali Hari Minggu (jika hari Minggu urgent bisa kontak via SMS)
Telegram:
@budi_s4n2s0, @owner_safana
WhatsApp:628112886854
Site : http://one.safana.co.id/

Timus

  • User OtomaX --
  • Hero Member
  • *****
  • Posts: 2,045
  • Otomax Advanced 3.7.2
Re: Import Excel data into SQL Server using copy and paste
« Reply #1 on: March 15, 2012, 08:45:50 PM »
kalau yg kebalikannya ada mas..
Kedaluwarsa: 05/09/2017