On one other hand SQL engine for SQL Server and Sybase are very a lot comparable, a minimum of syntactically, and in case you are migrating queries from SQL Server to Sybase you can do this with out a lot trouble, in fact, there shall be slight adjustments however not as a lot as Oracle.
So, in case you are migrating from Oracle to Sybase or SQL Server it is almost definitely the identical job and it’s best to first begin with both SQL Server or Sybase ASE after which later migrate them from one another.
On this Oracle and SQL Server tutorial, we are going to see a few examples, the place Oracle and SQL Server are totally different and the way to change these SQL queries in order that they’ll run on Microsoft SQL Server.
Migrating SQL queries from Oracle to SQL Server
As I stated, we confronted three predominant issues whereas migrating our SQL queries from Oracle to SQL Server, these are associated to SEQUENCE object, order by clause in subqueries, and utilizing nameless derived tables. Let’s see them one after the other.
1. Order by in subquery or derived desk
Error: The ORDER BY clause is invalid in views, inline features, derived tables, subqueries, and customary desk expressions until TOP or FOR XML can also be specified.
With a purpose to clear up this drawback you want to take away order by clause from subquery and derived desk and transfer these to the principle consequence set, more often than not you are able to do that however if you cannot then you definately in all probability must rewrite the entire question.
The beneath question will work in Oracle however won’t work in Microsoft SQL Server, as it’s utilizing order by clause in a subquery:
choose CUSTOMER_ID,CUSTOMER_ADDRESS from CUSTOMER the place CUSTOMER_IDS IN (choose SELLER_ID from TRANSACTIONS the place ITME_TYPE='PC' order by PURCHASE_DATE)
With a purpose to make it work we have to take away order by clause from subquery and like beneath:
choose CUSTOMER_ID,CUSTOMER_ADDRESS from CUSTOMER the place CUSTOMER_IDS IN (choose SELLER_ID from TRANSACTIONS the place ITME_TYPE='PC')
2. Derived desk and not using a identify
The second distinction I discovered between Oracle and SQL Server question is that oracle permits you to question derived tables and not using a specifying identify however SQL Server does not permit it. Take a look at the next question, which works completely in Oracle however provides syntax error in SQL Server :
choose depend(*) from ( choose BUYER_ID from TRANSACTIONS the place SELLER_ID= 'james_2012' and item_type='PC' UNION choose SELLER_ID from TRANSACTIONS the place BUYER_ID= 'james_2012' and item_type='PC' )
Error: Incorrect syntax close to ‘)’
Answer:
This error was extraordinarily straightforward to repair, we simply want to supply a reputation to our derived desk utilizing “as” key phrase, right here is the modified SQL question which is able to work in Sybase and Microsoft SQL Server 2005, 2008 and could also be in one other model :
choose depend(*) from ( choose BUYER_ID from TRANSACTIONS the place SELLER_ID= 'james_2012' and item_type='PC' UNION choose SELLER_ID from TRANSACTIONS the place BUYER_ID= 'james_2012' and item_type='PC' ) as sells
3. SEQUENCE Object
The one resolution was to take away the SEQUENCE code and as a substitute use the IDENTITY function of SQL Server, which is just like sequence and creates routinely incremented columns. You present IDENTITY a seed and an incremental worth, the default is (1,1) and it routinely generates numbers for yours.
Briefly Oracle, pagination queries run superb on SQL Server besides few adjustments talked about above like order by clause inside subquery or derived desk.
By the way in which, these had been a number of the most typical adjustments, you want to make to run your oracle question into the SQL server. In case you have additionally finished the identical job then please tell us what sort of subject you will have confronted on the SQL Server aspect and the way did you clear up it. Hmm, feels like query?
P. S. – By the way in which, I’ve additionally written a few posts on queries like 10 methods to make use of SQL SELECT queries and Don’t delete, truncate it. When you like studying extra on SQL queries then these are for you.