Q: What is CTE and how does it help in Improving the performance.
A : CTE as Common Table Expression. They are also called disposable Views. But there are some difference too. Like CTE can be recursive and can not be indexed. They tend to use the Existing indexes.
Syntax :
With cte as (select * from table1)
select * from table2 join cte on cte.key1 = table2.key2
----------------------------------------------------------------------
They are just like a table, so you can join on them and can not use them in where clause.
They can basically used to write neat SQL. But if you have some table calls written repetitive in lots of joins , you can put them in a CTE and use CTE. I have seen lots of performance in SQL optimization in this case.
For any questions i can help you with CTE problems, please comment down below.
A : CTE as Common Table Expression. They are also called disposable Views. But there are some difference too. Like CTE can be recursive and can not be indexed. They tend to use the Existing indexes.
Syntax :
With cte as (select * from table1)
select * from table2 join cte on cte.key1 = table2.key2
----------------------------------------------------------------------
They are just like a table, so you can join on them and can not use them in where clause.
They can basically used to write neat SQL. But if you have some table calls written repetitive in lots of joins , you can put them in a CTE and use CTE. I have seen lots of performance in SQL optimization in this case.
For any questions i can help you with CTE problems, please comment down below.
No comments:
Post a Comment