Multi-condition table Filtering

Source: Internet
Author: User

Attackers can bypass the database.

I didn't think about the question. It's easier to understand it. The answer is simple, but I have taken a detour.

There are two tables with the same structure: content as C, content_temp as T. The primary key is ID

Table t contains part of table C data. The condition that the title and answer are the same is used to determine whether the data exists in both tables. If so, the data in table t is deleted.

The first response builds a statement like this:

Delete from content_temp t where T. Title in (select title from content) and T. Answer in (select answer from content)

You can only find one in condition. Neither of the two in databases knows what to do.

Later, we did this and used a cursor loop to achieve the effect.

View code 1 declare @ title nvarchar (max );
2 declare @ answer nvarchar (max );
3
4 declare mycursor cursor
5 select title, answer from content;
6
7 Open mycursor;
8 fetch next from mycursor
9 into @ title, @ answer;
10
11 while @ fetch_status = 0
12 begin
13 print @ title;
14 Delete from content_temp
15 where title = @ title and answer = @ answer
16 fetch next from mycursor
17 into @ title, @ answer;
18
19 end
20
21 close mycursor;
22 deallocate mycursor

23 go

 

The result is that the execution speed is very slow, especially the large data volume. I have 0.3 million data records. I gave up the execution in five minutes. It is estimated that the execution will be completed in at least one hour, this is because there are too many loops.

The final solution is:

Delete from content_temp where ID in (select T. ID from content_temp tinner join content C on T. Title = C. Title and T. Answer = C. Answer)

Why can't we think of such a simple question after turning around? Attackers can bypass the database.

PS: When can I solve the bug not displayed in the blog garden code?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.