Link to home
Start Free TrialLog in
Avatar of Vijay
Vijay

asked on

copy data in SQL Server

While i try to copy data from one table to another table in sql server 2008 i am getting below error.

There is already an object named 'table123' in the database.

Just i am copying this table to another database.

i already created schema in another database with same table name.
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

There is already an object named 'table123' in the database.
are you using Select ... Into statement for data copying?

try use a Insert into ... Select statement instead.

OR else you need to drop that table before running your existing statement.
Avatar of Vijay
Vijay

ASKER

I used select * into .
If i use select * into, it is creating table and copying data. But it not creating constraints.
It will not. Furthermore, please be aware that the metadata tables, such as sys.tables, sys.columns are exclusively locked during the execution of such statement and as such this isn't quite a good practice in case of large table in production environment.

Better still, just create a script from original table (with constraint of, course), change table name in the script, execute the script and then import the data with the help of insert into...select from
ASKER CERTIFIED SOLUTION
Avatar of Vikas Garg
Vikas Garg
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Vijay

ASKER

Thank you Vikas