Solved

How do I copy entire data to different Table

Posted on 2007-12-04
4
193 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
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
Ashish Patel earned 250 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
kill process lock Sql server 9 65
Query group by data in SQL Server - cursor? 3 49
MySQL Query Using Up Memory 6 43
Accessing variables in MySQL query 4 33
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

830 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