Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8314519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:50:47+00:00 2026-06-08T20:50:47+00:00

I am trying to run a code to insert rows from one table using

  • 0

I am trying to run a code to insert rows from one table using rows from a different table on a different database.
I had this:

INSERT [testDB].[dbo].[table1]
SELECT * FROM 
[sourceDB].[dbo].[table1]
LEFT OUTER JOIN [testDB].[dbo].[table1] 
ON [sourceDB].[dbo].[table1].[PKcolumn] = [testDB].[dbo].[table1].[PKcolumn]
WHERE [testDB].[dbo].[table1].[PKcolumn] IS NULL

However I was told to add correlation names so I made this:

INSERT test
SELECT * FROM 
[sourceDB].[dbo].[table1] as source
LEFT OUTER JOIN 
[testDB].[dbo].[table1] as test
ON 
source.[PKcolumn] = test.[PKcolumn]
WHERE test.[PKcolumn] IS NULL

I ended up getting this as an error message:

Msg 208, Level 16, State 1, Line 1
Invalid object name ‘test’.

Does anyone know what I’m doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:50:49+00:00Added an answer on June 8, 2026 at 8:50 pm

    In the first line you should use the real table name as in

    insert into testDB.dbo.table1

    SQLServer does not accept an alias or correlation name in that spot, and I confirmed that by testing.

    But you can use the alias later in the query and it can be quite useful to do so to avoid ambiguity about which table a column comes from.

    Another potential problem in this query is the use of select *. This tries to insert the combined column set from sourcedb.dbo.table1 and testdb.dbo.table1 into testdb.dbo.table1. That can’t work.

    Instead of select * you could say…(assuming source and test have exactly the same columns)

    select source.*
    

    or you could call out the specific columns as in…

    select source.colA, source.col3, etc....
    

    I don’t know the names of your columns.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to run this code: ItemTaxonomy iTaxonomy = from itemTaxonomy in connection.ItemTaxonomy
I am trying to insert rows into a MySQL database from an Access database
I am trying to insert a few rows into the MySQL table using Codeigniter
I'm trying to run this code using tomcat in eclipse <%@ page language=java contentType=text/html;
I'm trying to run this code but this error appear: Uncaught TypeError: string is
I'm trying to run this code: let coins = [50, 25, 10, 5, 2,1]
I am trying to run this code : exec myStoredProcedure Cast('c5b48202-36af-4597-9780-5366d4188f55' AS uniqueidentifier), 744,
I'm trying to run the code from here MDN: Generators and Iterators function fib()
when I trying to run following code. var result = from c in db.brand
I'm trying to run the code below to insert a whole lot of records

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.