Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I copy entire data to different Table

Posted on 2007-12-04
4
Medium Priority
?
215 Views
Last Modified: 2010-03-19
Hello. I have MS SQL 2005
I have two tables in same DataBase.
I want to copy Test table into DealerTable
1. Test
DealerName nvarchar(255)
DelaerMPA


2.Dealer
DealerID       int   Primarykey
DealerName nvarchar(255)
DealerMPA  int


How do I do it?
0
Comment
Question by:erin027
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
Ashish Patel earned 1000 total points
ID: 20401948
1. Change Dealer table defination and set IDENTITY(1,1) to DealerID
2. Insert Into Dealer (DealerName, DealerMPA) Select DealerName, DealerMPA From Test

all should be good.
0
 
LVL 25

Expert Comment

by:imitchie
ID: 20402029
Is Dealer completely empty? - doesn't really matter
Is DealerID an identity column? - assume no

insert into Dealer
select row_number() over (order by DealerName), DealerName, DealerMPA
from Test
0
 
LVL 25

Expert Comment

by:imitchie
ID: 20402037
Is Dealer completely empty? - NO. Okay try not to clash with existing PK
Is DealerID an identity column? - assume no

insert into Dealer
select isnull((select max(DealerID) from Dealer),0) + row_number() over (order by DealerName), DealerName, DealerMPA
from Test
0
 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 20402069
since dealerid is a primary key we cannot insert it directly. so that we can do a small workaround assuming that I am adding 7 with delaermpa and using it as dealer Id. This is just to give idea for our situation.Please note that the fieldname in Test table is delaermpa. if it is correct then proceed or else change the fieldname in the below given query

insert into dealer  select '7'+left(delaermpa,1) as dealerid, * from  test
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question