Automated SQL Server slow query report? - sql-server

I am a developer and performance tester but not a DBA. My team is working on a performance testing tool that is specific to our software. One of the features we want it to have is the ability to generate a database report immediately after the test. Our software is database agnostic. For Oracle, I can easily create a snapshot id before and after the test and programmatically create an AWR report for those snapshots, write to a file and save with other artifacts we gather. Works great.
For SQL Server, however, there is no AWR equivalent (that I know of). I know the MDW as part of the SSMS has a UI for getting things like top 10 slow SQL and things like that. But, I have not yet found a way to programmatically create and extract a SQL performance report (preferably similar to Oracle's AWR) for SQL Server.
I am even willing to create the report myself if I can find a way to extract the raw data.
Any ideas would be greatly appreciated because searching online is not getting me anywhere.
P.S. I'm trying to do this in Java, by the way, but will accept help in any language. Thanks again!

Good news! In SQL Server 2016, you can use Query Store. This is like your flight recorder blackbox.. finding long running queries and waits. Capture baseline built in to SQL Server. You can compare before and after hardware changes and/or upgrades on queries. Maybe this similar to Oracle AWR.
Only available SQL Server 2016 and up.

Related

Compare Databases in SQL Server 2008

I had to provide a web application creatde in ASP.net and C# to my client. After some time he wants to make changes in that product. I have to update in code and database. So please provide some idea or guidance that how to compare the database using SQL Server 2008.
Or can I do this with other software?
I have googled but I got not enough satisfaction. Thanks...
We use SQL Compare by Redgate.
It's very easy to use - it will show you the differences between two databases and allow you to select which objects you want to synchronise. A synchronisation script is then generated that you can run on the target database.
Easy peasy!

10,000 foot overview question on SQL Server query composition

I've just migrated from Access where I would "write" SQL constantly and quickly using their GUI layout. I'm very new to SQL Server and am puzzled why is there no query GUI in SQL Server. Is it just that much more powerful that a GUI wouldn't be able to address the majority of queries? Or is it like a purist thing where once one is no longer in watered down databases like Access that he or she should just know SQL well enough to write it on the fly. Or am wrong altogether, and there IS a graphical way that most programmers compose SQL?
Sorry for the umbrella question, but I think some theory here would help me understand the big picture better.
I think there is a Query Designer as part of Sql Server Management Studio: see for example SQL Server 2005 Management Studio Query Designer.
The SQL Server is a database server. That it self does not have any editor text or GUI. You can mange it from the console, or any dedicated software that might have or not a query designer.
The main difference between Access and SQL Server or any other database, is that the MS Access is application that store the data in a file, when You close "Access" anything can happen inside the database by it self, while you are using SQL Server it is alway on You only connect to it. That why access have build nice query, report form designers. The SQL Server has totally different job to do and does not need this. With SQL Server we have Sql Server Management Studio, whit serve to global management not only for table creation and query design, there is a lot of background staff going on right there for example user management, rights jobs.
So it is not that SQL Server does not have a query designer, You just don't use proper software to work with it. A power full application is SSMS that ChrisW presented.
Actually there is a GUI-Designer for Views and Queries. Just use the SQL Server Management Studio.
For Example on the "Views" right-click and choose "Add View...". The view GUI is looking very similar to the one in access.
AFAIK about MySQL. Earlier there was the MySQL suite of tools and now there is the MySQL Workbench.
Say what you may, but it's definitely a timesaver.
First off, I believe the query designer in SQL Server Management Studio is probably the equivalent of what you've used in Access. I'm not terribly well-versed in using Access except through code, but I think you can do what you want there (in query designer). I've never found it to be very flexible, so I always end up back in the code itself, but there you go.
My other answer is a little bit off topic (and posted at this point mostly for googlers), but if you're a developer (especially using SQL Server), it probably still applies: Linq to SQL in Visual Studio.
I've been developing against SQL Server databases for about 7 years now, and most of that time has been spent writing the SQL statements out by hand. Last year, I changed jobs and finally had an environment where the databases my programs used were local and didn't change structure. I finally had a good opportunity to begin using Linq!
Linq is an amazingly useful tool!!! I now use it for almost (not quite) all of my database interactions from code.
The basic gist is that you create a graphical database layout in a dbml file. This layout includes tables (or views) as objects and association (PK/FK relationships) as links between the objects. How you set up the associations determines whether that property is a single object or an entity set of that object. Imagine you've got the following:
TABLE (ORDERS) TABLE (CUSTOMERS)
-------------- ----------------
PrimKey
CustomerID --(FK)--> PrimKey
OrderDate CompanyName
Using Linq to SQL, when you run something like the following:
Using db as new DataBaseContext
Dim orders = (From iOrder In db.ORDERS Order By iOrder.Customer.CompanyName).ToList
End Using
You end up with a list of Order objects that each own its corresponding Customer object. You can set this up to have object hierarchies and it pretty much works like you'd expect.
Anyway, it's a fairly big topic and more to get into than is appropriate here, but suffice to say that I think it's a great technology to bridge graphical interaction with true, nitty-gritty code.

How to automatically store data from Oracle in SQL Server (according to a schedule)

Hello,
I'm new here, so sorry, if my question is too basic. However, maybe you have some advice, example, links, which could help me... I'm trying to find something helpfull for few days, but no results as for now.
I'm working in a distributed environment. I have a Oracle server hundreds of miles away and a MS SQL server close to me. I'm writing a application using Visual Web Developer 2008 Express. I need some data from Oracle. It's not worth to query the Oracle server every time i need some data from it. I'd prefer to run some Oracle queries once each night and store results in some local (SQL Server) tables. I assume, I should run queries through standard windows scheduler (Windows Server 2008). I have the basic connectivity - I can open Oracle Database from local Visual Studio.
The questions are:
How to write a query/procedure/function that would get data from Oracle and put them into a SQL Server table (possibly recreated before each query run)?
How can I run such a query from command line (or in other way run from scheduler)
What naming conventions are applicable? In VS I use something like //IP.IP.IP.IP/Name and a user with password.
Thanks for any help or advice.
Regards,
Matteo
I suggest you speak to the DBA's of the Oracle and SQL Server databases, as there may be other considerations you need to bear in mind. (Data Integrity, Security, ownership etc.)
One route you could follow would be to implement DTS (For older databases) or SSIS (for new versions of SQL Server) processes to copy the data across on the schedule you want. (This is pretty much what they were built for.)
How much data are we talking about?
If there is a small quantity that you need to transfer every day, you can write a stupid fetch and insert script in language of your choice.
You only need to search for better solutions if "sync" would take too much resources.
Thanks...
I'm the DBA for the SQL Server, which will serve only for my application. For Oracle I just want to read data and I have enough privileges and agreement with DBA's. Security, ownership and integrity are not an issue for now. I just need some technical advise how to get data from Oracle to MSSQL tables on a schedule.
I use MS SQL Server 2008 Express SP1. I'm very close to solve my problem - I have established connections and everything installed and working. I just don't know, how to run a query, which would get data from Oracle and put into MSSQL, on regular basis, without manual interaction.
I've some experience in programming, but not much in databases (except creating complex SQl queries). Therefore some example or links to detailed description would be helpful. I'm not sure about naming conventions, differences between procedures, functions and queries, command line options to run db automation procedures and so on. I'm also not sure, about which mechanisms or technologies are available in MS SQL Server 2008 Express edition.

SQL Server Compact - Schema Management

I've been searching for some time for a good solution to implement the idea of managing schema on an SQL Server Compact 3.5 database.
I know of several ways of managing schema on SQL Server Express, SQL Server Standard, SQL Server Enterprise, but the Compact Edition doesn't support the necessary tools required to use the same methodology.
Any suggestions/tips?
I should expand this to say that it is for 100+ clients with wrapperware software. As the system changes, I need to publish update scripts alongside the new binaries to the client. I was looking for a decent method by which to publish this without having to just hand the client a script file and say "Run this in SSMSE". Most clients are not capable of doing such a beast.
A buddy of mine disclosed a partial script on how to handle the SQL Server piece of my task, but never worked on Compact Edition. It looks like I'll be on my own for this.
What I think that I've decided to do, and it's going to need a "geek week" to accomplish, is to write some sort of a tool much like how WiX and NAnt works, so that I can just write an overzealous XML document to handle the work.
If I think that it is worthwhile, I'll publish it on CodePlex and/or The Code Project because I've used both sites a bit to gain better understanding of concepts for jobs I've done in the past, and I think it is probably worthwhile to give back a little.
Edit on 5/3/2010:
If someone is willing to "name" the project, I'll upload the dirty/nasty version that I've written for MS SQL to CodePlex so that maybe we can start hacking out a version of SQL Compact. Although, I think with the next revision of the initial application that I was planning, I'm going to be abandoning SQL Compact and just use XML Files for storage, as the software is being converted from an Installable package to being a Silverlight application. Silverlight just gives a better access strategy.
I am currently looking into Migrator.Net.
This allows you to write changes to your database, called migrations, directly in C#.
These migrations can contain everything from simple table additions/drops, column modifications, to complicated data update code.
When your application boots, it can verify what version the database is currently in and apply any migrations that are required to bring it up to date. All this is handled automatically. The code to run this update is as simple as:
Assembly asm = Assembly.Load("LocalModels.migration");
Migrator m = new Migrator("SqlServerCe", "Data Source=LocalModels.sdf", asm, false);
m.MigrateToLastVersion();
I am having a couple minor issues with the Compact support (it assumes the default schema is dbo). But I don't think it will be too difficult to fix them.
some random thoughts (not sure I can fully answer though)
the Microsoft Sync Framework is one option. I haven't had a chance to fully appreciate what it can do once you've deployed it after the initial first time (which seems to work fine). There's a MSDN site for it here
You can execute scripts on a mobile device, but not through something like SQL Management Studio, so in theory you could manage/maintain T-SQL scripts but the down side is that the T-SQL would be convoluted (to CE's supported statements) and I don't know a way to "automate" execution - but the Sync Framework might hold some answers..
If one of your key criteria is going to be working efficiently over a small pipe, the only real choice you have is to store a DB Schema Version (maybe somehow tied to the scripts checked into your CMS) and when an update is needed, the change scripts are sent over the wire and applied in order. You would probably want to keep a log in your DB as well of these scripts being applied so you can gracefully handle disconnects, reboots and other potentially nasty problems.
Is SQL Server Management Studio any use for you?
http://technet.microsoft.com/en-us/library/ms172933.aspx

Fast SQL Server 2005 script generation

It seems like the generation of SQL scripts from the SQL Server Management Studio is terribly slow. I think that the old Enterprise Manager could run laps around the newer script generation tool. I've seen a few posts here and there with other folks complaining about the speed, but I haven't seen much offered in the way of alternatives.
Is there a low-cost/free tool for scripting an entire SQL Server 2005 database that will perform better that SSMS? It would be hard to do worse.
See the Database Publishing Wizard that is part of the SQL Server Hosting Toolkit. It generates a single SQL file for both schema and data.
We are using the tools by RedGate which I personally find very useful in any aspect of work with databases. For scripting I would recommend the SQL Compare (you need a pro version for scripting). The SQL Compare is a must have for deploying schema changes from the deployment DB to the live Server and a real timesaver.
Those tools are not free but I think they could save you money in a long run
What kind of scrpt generation are you talking about now?, generating create scripts from the objects in the database is way faster in SSMS compared to EM.
But if you are running an select or something that gives you lots of rows in the grid, it is crazy slow.. like scripts generating inserts statements of all rows in an table, if you got lots of data, it is almost not doable.
I don't know what is "terribly slow" for you, but I have a decent performance with SQL 2005 Management Studio. In either case, RedGate products are very cool. Unfortunately they are not free.

Resources