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 5928085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:15:08+00:00 2026-05-22T14:15:08+00:00

I must import lines from a file into database. I must check if foreign

  • 0

I must import lines from a file into database. I must check if foreign key exists. Here a sample of lines I should import :

A   481 11/23/1981  12  77000   DESCRIPTION_1     $5,098
A   482 11/23/1981  15  77000   DESCRIPTION_1     $5,098    
A   482 11/23/1981  12  77000   DESCRIPTION_1     $5,098
A   481 11/23/1981  9   77000   DESCRIPTION_1     $5,098
A   481 11/23/1981  12  77000   DESCRIPTION_1     $5,098
A   481 11/23/1981  12  77000   DESCRIPTION_1     $5,098
A   481 11/23/1981  1   77000   DESCRIPTION_1     $5,098
A   481 11/23/1981  1   77000   DESCRIPTION_1     $5,098
A   481 11/23/1981  1   77000   DESCRIPTION_1     $5,098
A   481 11/23/1981  1   77000   DESCRIPTION_1     $5,098

Here the foreign key are 12, 15, 9, 12, 1. I want to check if one of these foreign key. In the sample the foreign key 12 does not exist. The simplest way is to test line by line :

SELECT COUNT(*) From TypeTable WHERE IdType = 12 -- 0
SELECT COUNT(*) From TypeTable WHERE IdType = 15 -- 1
SELECT COUNT(*) From TypeTable WHERE IdType = 9  -- 1
SELECT COUNT(*) From TypeTable WHERE IdType = 12 -- 1
SELECT COUNT(*) From TypeTable WHERE IdType = 1  -- 1

The problem with this method is that there is one query for each different foreign key, and files I should import has thousands lines (and potentially thousands foreign key).

So I want to know if it’s possible to use the “set feature of SQL” to retrieve in one query but I don’t know how to do this…

PS : In the result of my query, I need to know the foreign key does not exist in database

Regards,

Florian

  • 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-05-22T14:15:09+00:00Added an answer on May 22, 2026 at 2:15 pm

    If the data has been loaded into a staging table then you can use this

    SELECT
        *
    FROM
       myStagingTable ST
    WHERE
       NOT EXISTS (SELECT *
                FROM TypeTable TT
                WHERE ST.FKCol = TT.IdType)
    

    To do something set based, you need a table with the desired FK values. This could be a temp table on the same connection and populated by scanning the file. The same SQL would work above by changing myStagingTable to #myFKTable

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

Sidebar

Related Questions

I have an access database on a windows machine, which I must import into
I got an XML file from 3rd party that I must import in my
I have a web project where I must import text and images from a
I need to import a mesh animation from Cinema4D into Blender . I tried
I have filter that I took from django but now I must import too
import smtplib SERVER = my.smtp.server.com FROM = myemail@somehost.ca TO = [someemail@somehost.mun.ca] # must be
I am trying to batch load some dummy content from a CSV file into
This must be a classic .NET question for anyone migrating from Java. .NET does
I must be overlooking something simple. I'm setting a variable from a query result
Code replicating the error: from sqlalchemy import create_engine, Table, Column, Integer from sqlalchemy.ext.declarative import

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.