Interview :: SQL
SQL or Structured Query Language is a language which is used to communicate with a relational database. It provides a way to manipulate and create databases. On the other hand, PL/SQL is a dialect of SQL which is used to enhance the capabilities of SQL. It was developed by Oracle Corporation in the early 90's. It adds procedural features of programming languages in SQL.
In SQL single query is being executed at once whereas in PL/SQL a whole block of code is executed at once.
SQL is like the source of data that we need to display on the other hand PL/SQL provides a platform where the SQL the SQL data will be shown.
SQL statement can be embedded in PL/SQL, but PL/SQL statement cannot be embedded in SQL as SQL do not support any programming language and keywords.
Yes. You can use the column alias in the ORDER BY instead of WHERE clause for sorting.
There are mainly two type of indexes in SQL, Clustered index and non clustered index. The differences between these two indexes is very important from SQL performance perspective.
- One table can have only one clustered index, but it can have many non-clustered index. (Approximately 250).
- A clustered index determines how data is stored physically in the table. Clustered index stores data in the cluster, related data is stored together, so that retrieval of data becomes simple.
- Clustered indexes store the data information and the data itself whereas non-clustered index stores only the information, and then it will refer you to the data stored in clustered data.
- Reading from a clustered index is much faster than reading from non-clustered index from the same table.
- Clustered index sort and store data row in the table or view based on their key value, while non-cluster has a structure separate from the data row.
There is a built-in function in SQL called GetDate() which is used to return the current timestamp.
Most commonly used SQL joins are INNER JOIN and LEFT OUTER JOIN and RIGHT OUTER JOIN.
Joins are used to merge two tables or retrieve data from tables. It depends on the relationship between tables.
Following are the most commonly used joins in SQL:
Inner Join: inner joins are of three type:
- Theta join
- Natural join
- Equijoin
Outer Join: outer joins are of three type:
- right outer join
- Left outer join
- Full outer join
Inner join:
Inner join returns rows when there is at least one match of rows between the tables. INNER JOIN keyword joins the matching records from two tables.
INNER JOIN
Right Join:
Right Join is used to retrieve rows which are common between the tables and all rows of a Right-hand side table. It returns all the rows from the right-hand side table even though there are no matches in the left-hand side table.
RIGHT JOIN
Left Join:
The left join is used to retrieve rows which are common between the tables and all rows of the Left-hand side table. It returns all the rows from the Left-hand side table even though there are no matches on the Right-hand side table.
LEFT JOIN
Full Join:
Full join return rows when there are matching rows in any one of the tables. This means it returns all the rows from the left-hand side table and all the rows from the right-hand side table.
FULL OUTER JOIN