SQL Server 2008 - With Clause - sql

In the Oracle database we had extensively used WITH clause in earlier project.
Now we are on SQL Server 2008 database. Do you suggest we can still use the WITH Clause in our SQL codes ? Does SQL Server 2008 support WITH clause ?
I mean does it improve the performance or does using WITH affect query performance in SQL Server 2008 ?

You can read more about it here:
https://learn.microsoft.com/en-us/sql/t-sql/queries/with-common-table-expression-transact-sql
and here:
https://learn.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-table
Depending on what it is you were specifically looking at.
Performance is very much dependent on what it is you are doing, you would need to post some examples.

Related

What is the difference between MSSQL and TSQL?

MSSQL and T-SQL are often thrown around as interchangeable synonyms on the web.
I know that T-SQL is a flavor of SQL used in many Microsoft products. Is MS-SQL actually another flavor of Microsoft owned SQL or is it just an umbrella term used by the Microsoft’s marketing department to refer to their server database solutions?
As a side question, what flavor SQL, if any, does MS Access use?
MS SQL is simply a short version of the (complete) product name Microsoft SQL Server. (Similar to "MS Office", "MS Windows" or "MS Access").
T-SQL is the SQL dialect that the product Microsoft SQL Server is using - and is short for "Transact-SQL" (thanks Aaron for reminding me!)
I wouldn't call the dialect that Microsoft Access is using SQL. It's a query language that somehow resembles SQL
The MS SQL Stands for ( Microsoft SQL). This is the product of Microsoft which they released MS SQL 2005, 2008 and recently released 2012.
T- SQL stands for Transact SQL. This is the syntax of writing the expression in the sql database. You can write T- SQL statments in MS SQL Server Database
Link to Refer

Adaptation of the merge clauses in SQL Server 2005

I have a code which is up and running but the problem that I have is that it includes a lot of MERGE clauses as it was intended to be run from SQL Server 2008 and forward. But the problem is that a new customer is running SQL Server 2005 and as you know the Merge clause is not available till SQL Server 2008, so my question is if there is not a way to parse the this clauses automatically or if there is another solution (apart from rewriting all the clauses in clasical clauses ) as the customer is not willing to upgrade the DB.
Thanks a lot in advance.
I am afraid that you will need to re-write all of your MERGE clauses for SQL Server 2005.
You can use the 2005 friendly output clause to achieve the same functionality but with more verbose SQL. This approach will also work on SQL Server 2008.
http://sqlserver-tips.blogspot.co.uk/2006/09/mimicking-merge-statement-in-sql.html
You could put together a C# (or whatever) app to parse the merge statements and create insert/update statements from them. I mean, that's a horrible idea, but you can do it...
You'd have to pull out the "ON" part, add it to a check IF EXISTS and the update part, then add the column list to the insert part. You could even programmatically (sic?) create SP params and everything.
Heh. Good luck.

Improve SQL Server query performance

I would like to know if there is any tool which will give me the optimized SQL query for which ever query I specify. So that I can improve my DB as well as query performance. I use SQL Server 2008.
Thanks in advance.
The old Rule of DBs still applies, don't try to optimize sql statements, since the DB query parser will do its own optimizations anyway, instead do right away what we all do in the end:
Create indexes to increase performance
Don't get me wrong of course sql queries can be written stupidly and will therefore perform badly, but as long as you created a sensable 'normal' query, the query optimizer will do the rest together with the indexes.
SQL Server will even tell you if a query will clearly benefit from an index when you look at the execution plan. It will even generate the DDL statement to create the index, so all you have to do is copy/paste and run it to have the index your query needs.
You can already watch the execution plan that gives you SQL Server Management Studio.
You can try Redgate, they have evaluation versions for most of their products:
Redgate Website
SQL Server 2005 and up comes with a Query Optimizer. This can help, but tools can't really do too much optimization suggesting for you because they don't know what you are trying to accomplish.
You might try taking a look instead at some ways in which you can optimize your queries. Here are some links to get you started.
Tips, Tricks, and Advice from the MS SQL Query Optimization Team
SQL Server Rules for Optimizing Queries, best practices
Statistics Used by the Query Optimizer in SQL Server 2008
SQL Server 7.0 / 2000 came with 'index tuning wizard' this functionality has been around for a long time.
I'd reccomend having a look at 'select * from sys.dm_db_missing_index_details'
It tells you which indexes are 'missing', it's trivial to look in that table and then create indexes

How can I post updates (commits) in oracle db to SQL Server 2005

We have an application (BaaN) on Oracle Database.
We also have an application that is on SQL Server 2005 which uses Oracle (BaaN) contents.
Currently we cache all contents of the Oracle DB to SQL Server nightly through linked server from SQL Server to Oracle.
Thought of using a trigger on Oracle db tables to write contents to Oracle table (DeltaCommits) as the commits occur, and then periodically look for entries in DeltaCommits from SQL Server using a scheduled job.
Or can you please suggest a better way to accomplish this ..
Thanks
It's possible to use replication to transfer data between Oracle and SQL server.
This guide looks like a useful starting point which may help you to decide whether this is a route you want to consider.

SQL Server 2000 vs SQL Server 2008 Query Performance

I'm working with a client who had a SQL Server 2008 converted from a SQL Server 2000 DB and one of the queries has quite dramatically increased in time since it was on SQL Server 2000.
However, if I change the compatibility level to 2008 in the DB, the query goes like a rocket (40-50 times faster).
The query does use a number of UDFs.
My questions:
- are there issues with running SQL2000 compatibility in SQL Server 2008
- has SQL Server 2008 improved the performance when using UDFs?
There are some other things you might want to do after upgrading. See the "After upgrading..." section here: http://msdn.microsoft.com/en-us/library/bb933942.aspx