Selecting data from a database table is very easy. We can write many types of select. But the tough part here is to choose the right select statement as per requirement. But always we have to think the performance for long term.
So we have to be cautious while writing SELECT query and need to remember the below points
So we have to be cautious while writing SELECT query and need to remember the below points
- Specify by all Key fields of tables while selection
- For single record if all primary keys matches, use SELECT SINGLE
- Otherwise use up to 1 rows
- Avoid select within loops / select .. Endselect
- Inner join / views better than nested selects / multiple selects
- Take care ‘For All Entries in Table’initial or Not
- Avoid fetching large number of records by SELECT *. Use specific fields
- Avoid Into Corresponding Fields into Table
These best practice rules are applicable in almost every project now a days to make the code safe for long term.