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

  • Home
  • SEARCH
  • 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 7037235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:31:12+00:00 2026-05-28T01:31:12+00:00

Possible Duplicate: sql server 2008 management studio not checking the syntax of my query

  • 0

Possible Duplicate:
sql server 2008 management studio not checking the syntax of my query

I ran across an issue today where a subquery was bad and the result was all rows from the parent table were deleted.

TableA
ID,
Text,
GUID

TableB
ID,
TableAID,
Text

delete from TableB
where id in (
  select TableAID
  from TableA
  where GUID = 'fdjkhflafdhf'
)

If you run the subquery by itself you get an error since the column (TableAID) doesn’t exist in Table A. If you run the full query – it deletes all records from table B without an error.

I also tried the following queries which removed 0 records (expected)

delete from TableB where id in (null) 
delete from TableB where id in (select null)

Can someone explain to my why this is occurring when the query is malformed? Why does it seem to evaluate to true?

Note: This was tested on SQL Server 2008 R2

  • 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-28T01:31:13+00:00Added an answer on May 28, 2026 at 1:31 am

    As TableAID doesn’t exist in TableA, the query is using the column from TableB. Therefore the query is the same as:

    delete from TableB
    where id in (
      select TableB.TableAID
      from TableA
      where GUID = 'fdjkhflafdhf'
    )
    

    So in essence it’s doing:

    delete from TableB
    where id in (TableAID)
    

    If you are using sub-queries its best to mention your table names when referencing. The following WILL throw an exception:

     delete from TableB
        where id in (
          select TableA.TableAID
          from TableA
          where TableA.GUID = 'fdjkhflafdhf'
        )
    

    Furthermore I would use an alias so that we know which query we are referring to:

     delete from TableB
        where id in (
          select a.TableAID
          from TableA a
          where a.GUID = 'fdjkhflafdhf'
        )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: SQL Server Database query help Hi, I have a problem that I
Possible Duplicate: SQL Comments on Create Table on SQL Server 2008 I just want
Possible Duplicate: Advantages of SQL Server 2008 over SQL Server 2005? What are the
Possible Duplicate: Change Notification with Sql Server 2008 Am just wondering is there's anyway
Possible Duplicate: Why are temporary tables not removed from tempdb in SQL Server? We
Possible Duplicate: SQL Server Express 2008 Install Side-by-side w/ SQL 2005 Express Fails I
Possible Duplicate: SQL Server - Query Short-Circuiting? Is the SQL WHERE clause short-circuit evaluated?
Possible Duplicate: Lost the IntelliSense SQL Server 2008 Intellisense problem In SQL Server 2008
Possible Duplicate: Best practice to create (on demand) SQL Server 2008 Express databases in
Possible Duplicate: app.config file in C# for MS SQL Server 2005 in VS 2008

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.