join the MSSQLTips community

Today's Site Sponsor


 

Find performance issues related to Analysis Services memory limits.
 


Insert data from Excel to SQL Server 2005 by using copy and paste commands
Written By: Kun Lee -- 2/8/2008 -- 0 comments -- printer friendly -- become a member




        Win SQL Books  -----  SharePoint Tips  -----  Live Webcast - SQL Backup Mistakes  -----  Bookmark and Share        

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


 

Next Steps

Readers Who Read This Tip Also Read Comment or Ask Questions About This Tip Twitter This Tip!


Sponsor Information
Free SQL Server performance monitoring dashboard – Idera SQL check

Increase your SQL speed and accuracy with code completion from SQL Prompt.

SQL Server Consultants - What you don't know could be your biggest asset - Guaranteed Results

Changing careers? Becoming a SQL Server Professional? Look no further...

Learn SQL Server 2008, Performance Tuning, Development, Administration, DR, Replication and more from these web casts

All SQL Server, all the time! Sign-up for the MSSQLTips newsletter!

Do you work on SharePoint too? Check this out...

Free Whitepaper - The Seven Steps to Successful SQL Server Auditing


 

 

Idera - SQL secure

Idera SQL secure collects and analyzes permissions data from SQL Server and Active Directory as well as the file system and registry to show who has access to what database objects and how that access is granted. SQL secure also monitors changes made to access rights so that unapproved changes can be easily identified and fixed. SQL secure also collects and evaluates key security settings within SQL Server and provides proactive recommendations to improve server security.

Download now!



More SQL Server Tools
SQL secure

SQL compliance manager

SQL defrag manager

SQL Backup

SQL Nitro




Copyright (c) 2006-2010 Edgewood Solutions, LLC All rights reserved
privacy statement | disclaimer | copyright | advertise | write for mssqltips | feedback | about
Some names and products listed are the registered trademarks of their respective owners.