Click here to Skip to main content
15,884,819 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am new to on SQL and I want to know that is there any tricky method for understanding someone's query in SQl? for example we developers generaly work on project, that written by a few years ago etc.etc. and when we face to database layer though sql we can not understanding what this query do?

What I have tried:

I improve my sql skills but still I have problem.
Posted
Updated 11-Oct-22 22:55pm
Comments
Member 8428760 11-Oct-22 16:36pm    
If there are no comments explaining it, then what I usually do is scan the query and find the tables that it uses. Then you can see what columns out of the tables they are pulling. The rest of the query will be filtering what data they pull and manipulating the data they get. The query types are select, insert, update, delete. Focus on the select type statements and the rest will be easy.

1 solution

You can't really understand a SQL query in complete isolation.

Try to understand what the author thinks they are returning from the database - where is the SQL used, what labels are used to describe the data in the Presentation layer, what is the title of the site/page/application - all these things can give you clues.

Next - see the comment from @User-8393253 - look at the tables and databases used. Is there any database documentation available, are the tables names / column names meaningful to help you work out what is happening - gain more clues.

Next - select sample data from the query (e.g. TOP 1000) - look at the data itself, what story is it telling you.

When you have finished all of that, have a better understanding of the database and the data then introduce peer review or other governance that insists on at least a minimum of documentation - e.g. comments that explain what the query is meant to do, for future use :laugh:
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900