Is there a log in SQL Server where I can read what commands have been executed? - sql

I'm using SQL Server 2008 and need to see a list of what commands have been exectued and when. Is this possible? How can I read such log?

Duplicated question (I guess)
Looking for a SQL Transaction Log file viewer
You can use third party software to read transaction logs.
http://www.red-gate.com/products/dba/sql-log-rescue/
http://www.apexsql.com/sql_tools_log.aspx
http://www.toadworld.com/products/toad-for-sql-server/w/wiki/10586.log-reader.aspx
And if you want to audit truncate command try to audit all commands executed on your database.
http://www.databasejournal.com/features/mssql/article.php/3861791/Database-Level-Auditing-with-Microsoft-SQL-Server-2008.htm

There are some commercial products which will do this like Apex SQL Log and I think Red Gate might do one too, which give you a nice GUI to do all this but it is possible to do all this without them. That being said, if you only need to do this once then you might get away with juts downloading and using a trial version of one of these products.
This tutorial shows you how to get started extracting information from the log using T-SQL and an undocumented function called fn_dblog. However, the caveat here, as always with undocumented features, is that you should not rely on it in production code in case it disappears without warning, which it may. If you're just using it to investigate something and not using it on a scheduled basis or anything then you'll be fine.
There are quite a few other tutorials out there that use fn_dblog as well, so just have a look on your favourite search engine. It is worth readin up on this function before using it as the information it returns isn't all that straightforward.

Related

How to run stored procedure every second automatically (sql server 2014 Express)?

I want to run stored procedure every second automatically.As I am using SQL Server 2014 Express edition so it is not possible to do the same with SQL Server Agent. Also, I don't have any third party tools to do so. I know it can be achieved by using Task Scheduler, sqlcmd utility or by using third-party tools but I don't know the exact way to do that.
I know this can be done and therefore I'm sure it's something I've missed but if anyone can share their experience of this I'd very much appreciate it.
Thanks.
This is a tough one. You're on the right track that you need an outside method to run the job, but I'd recommend writing one yourself to do it if you need the frequency every second (and also question if you really need it every second or not). A service or light application would be the best way to handle it.
I've written an article on setting up Task Scheduler for automated jobs on SQL Server Express, but that has a limit of once/minute. You would use the sqlcmd utility in this case.
You can look at third party utilities like JAMS Scheduler, but their community edition is only free for a year.
That being said, I don't know of any quick-and-easy methods that satisfy your frequency requirements as stated.

How can I see which tables are changed in SQL Server?

I have a database which I didn't make and now I have to work on that database. I have to insert some information, but some information must be saved in not one table but several tables. I
can use the program which have made the database and insert information with that. While I am doing that, I want to see that which tables are updated. I heard that SQL Server Management Studio has a tool or something which make us see changes.
Do you know something like that? If you don't, how can I see changes on the database's tables? If you don't understand my question, please ask what I mean. Thanks
Edit : Yes absolutely Sql Profiler is what I want but I am using SQL Server 2008 R2 Express and in Express edition, Sql Profiler tool does not exist in Tools menu option. Now I am looking for how to add it.
Edit 2 : Thank you all especially #SchmitzIT for his pictured answer. I upgraded my SQL Server Management Studio from 2008 R2 express edition to 2012 Web Developer Edition. SQL Profiller Trace definitely works.
I agree with #Lmu92. SQL Server Profiler is what you want.
From SQL Server Management Studio, click on the "Tools" menu option, and then select to use "SQL SErver Profiler" to launch the tool. The profier will allow you to see statements executed against the database in real time, along with statistics on these statements (time spent handling the request, as well as stats on the impact of a statement on the server itself).
The statistics can be a real help when you're troubleshooting performance, as it can help you identify long running queries, or queries that have a significant impact on your disk system.
On a busy database, you might end up seeing a lot of information zip by, so the key to figuring out what's happening behind the scenes is to ensure that you implement proper filtering on the events.
To do so, after you connect Profiler to your server, in the "Trace properties" screen, click the "Events Selection" tab:
You probably are good to uncheck the boxes in front of the "Audit" columns, as they are not relevant for your specific issue. However, the important bit on this screen is the "Column filters" button:
This is where you will be able to implement filters that only show you the data you want to see. You can, for instance, add a filter to the "ApplicationName", to ensure you only see events generated by an application with the name you specify. Simply click on the "+" sign next to "Like", and you will be able to fill in an application name in the textbox.
You can choose to add additional filters if you want (like "NTUsername" to filter by AD username, or "LoginName" for an SQL Server user.
Once you are satisfied with the results, click "OK", and you will hopefully start seeing some results. Then you can simply use the app to perform the task you want while the profiler trace runs, and stop it once you are done.
You can then scroll through the collected data to see what exactly it has been doing to your database. Results can also be stored as a table for easy querying.
Hope this helps.
Although you describe in your question what you want, you don't explain why you want it. This would be helpful to properly answer your question.
ExpressProfiler is a free profiler that might meet your needs.
If you're looking to track DDL changes to your database, rather than all queries made against it, you might find SQL Lighthouse useful, once it is released in Beta shortly.
Disclosure: I work for Red Gate.
Do you know something like that? If you don't, how can I see changes
on the database's tables? If you don't understand my question, please
ask what I mean. Thanks
Red gate makes a lot of great tools. You can always make a database comparison. That will require that you make a backup, then doing whatever you want to do, and the compare the two databases, there is a free trial, works perfect to compare which tables has changed (deleted/inserted and modified)
http://www.red-gate.com/products/sql-development/sql-data-compare/
what you might maybe be looking for is "SQL Server Profiler". It's a SQL monitor where you can see all the SQL queries running real time.
http://technet.microsoft.com/en-us/library/aa173918(v=sql.80).aspx
Hope that helps you.
As far as I know SQL Profiler tool is not included in the Express edition of SQL Server (only Developer edition contains it). Maybe you can purchase it separately.
If you want you can try this https://sites.google.com/site/sqlprofiler/ free tool for profiling. Maybe it has limitations, but it you can check it.
There are also some profiling tools for integration with Visual studio, and also the ReSharper has InteliTrace (if you are using the tool at all).
Cheers.

SQL Server - Checkout system for database objects?

I was wondering if anyone knows any 3rd party tools or existing functionality in SQL Server 2008 so that when someone is working on a table or procedure, it is locked out to that individual. I have searched the net extensively and can't seem to find anything relating to this. We are facing a problem where two people may be working on the same stored procedures and whoever executes last gets the code change! This kind of functionality would come in handy. I think that a lock or check in/check out system would be benefit a project, any ideas?
I am already hooked up to Redgate source control, which does not provide this functionality.
Thanks
Try and have a look at this SO discussion: How do I version my SQL Server database in SVN?
It might not lock things like you want, but it would help to ensure code is recoverable. You could also consider using DDL triggers as some kind of a checking mechanism.
you could try this: http://www.apexsql.com/sql_tools_version.aspx
Alternatively, try this: http://www.red-gate.com/products/sql-development/sql-source-control/entrypage/5-minutes?utm_source=google&utm_medium=cpc&utm_content=unmet_need&utm_campaign=sqlsourcecontrol&gclid=CK_qsPC5prUCFe7MtAodzC8ACA

SQL Server activity monitor show all queries

I'm using SQL Server 2005, and I'd like to know if there is any possibility to watch every query sent to SQL server?
SQL Server Management Studio has a built-in tool called the Activity Monitor which gives me nearly what I am searching for in the "Recent Expensive Queries Pane"
This pane shows information about the most expensive queries that have been run on the instance over the last 30 seconds.
I need exactly this for all recent queries, not just the expensive ones...
Can anyone help me?
Name a tool, or give me a hint what to search for...
To watch every query sent to SQL server using SQL profiler, you can use one of SQL Profiler predefined templates. It's TSQL_Duration.
It's designed to track completed stored procedures and TSQL code.
The trace will show you exactly the batch executed.
You can expand the events tracked and columns shown.You can find more information here: How To: Use SQL Profiler
The same feature is also available in ApexSQL Comply, an auditing tool that uses SQL traces to capture the events, then stores them in a central repository database, and provides built-in and custom reports where you can easily filter the transactions, and export them as Excel, Word, or PDF files.
Disclaimer: I work for ApexSQL as a Support Engineer
You're looking for SQL Profiler, it's usually installed along with SSMS.

Tools to Replay Load on a SQL Server

Has anyone come across any good tools (preferably but not necessarily FOSS) that can read a SQL Server (2005/2008) trace file and execute the commands against another database. We are attempting to perform some performance testing on our SQL servers and would like to replicate an actual load.
I have come across but not yet used:
JMeter
ReplayML
Preferably, the application would be able to use threading to mimic user connections and query execution on the SQL Server.
You can replay a SQL Server Profiler trace against another server using the SQL Server Profiler itself.
See the following Microsoft Reference as a starting point.
http://msdn.microsoft.com/en-us/library/ms189604.aspx
Quest Software also have a tool called Benchmark Factory that can be used to perform SQL Server load testing.
http://www.quest.com/benchmark-factory/
One of the best tools is actually freely available from Microsoft. The RML Utilities are targeted at SQL2005 & SQL2008 and are specifically designed for this type of testing.
You can download the tools from http://www.microsoft.com/downloads/details.aspx?FamilyId=7EDFA95A-A32F-440F-A3A8-5160C8DBE926&displaylang=en
We have used them to solve several performance and locking issues.
Note: Capturing trace files using the SQL Profiler GUI can add to performance problems due to the way the GUI and Trace backend interact. The RML Utilites include a script that can capture traces directly from the SQL Server without using the GUI.
You can replay trace files directly in SQL Profiler, although I've only used it a couple of times for that, so I don't know what all of the limitations are on it.
team system has an add-on that you can find on codeplex: It is called ->
sql load test
Let me know if that works well for you.
I know this is a really old question but after searching for some time i discovered a new open source tool.
https://github.com/spaghettidba/WorkloadTools which works great