Daniel R.
Daniel R.

Reputation: 1

Copy a table to another database

First of, I'm beginner in T-SQL so this question might be silly. Sorry about that.

I am trying to copy a table to another database like this

USE Datatable
GO
     SELECT *
        INTO Datatable.HumanResources.Employee
        FROM AdventureWorks2012.HumanResources.Employee
        WHERE 1=0

And I get an error :

"Msg 2760, Level 16, State 1, Line 2
The specified schema name "HumanResources" either does not exist or 
you do not have permission to use it." 

Do I have the permissions or I just can't reuse the Adventureworks schema like that or Alter privileges somehow? Help.

Upvotes: 0

Views: 213

Answers (2)

Ilessa
Ilessa

Reputation: 622

Does Datatable.HumanResources.Employeealready exist in your new database with the same columns and types already?

It's also worth checking that the user which you are connecting to SQL as has the appropriate permissions on both databases, as you are getting a permission error.

Your WHERE 1=0 (Which I believe you got from here) will only create a blank table with the columns from the other table.

The correct query you need would be

USE AdventureWorks2012
GO

SELECT *
INTO HumanResources.Employee IN Datatable
FROM HumanResources.Employee

Upvotes: 1

jradich1234
jradich1234

Reputation: 1425

Does the HumanResources scheme exist in both you source and destination databases? Also, I'm wondering why you haveWHERE 1=0. Even if you did not have this error, that query would never copy any rows.

Upvotes: 0

Related Questions