SQL Server 2005 support for Oracle-style autonmous transaction - sql-server

Within a transaction is there a way to have data committed within it even though the transaction is rolled back? We're writing audit/logging information inside a transaction but we want to keep that information even though the transaction has to roll back.
We've see an article that tries to copy the Oracle way but what we're really looking for is some in-built SQL Server support (and was hoping for something like a 'not supported' option for a sproc or a 'suspend transaction' command.) Google searches have been a bit hopeless hence this post.

Unfortunately, this may be the only way but for SQL Server 2008, but it does mention options for SQL Server 2005
How to create an autonomous transaction in SQL Server 2008

Microsoft considered the idea in a simpler approach for 2008 and then dropped it:
http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=296870
but there is another work around on their website.

Related

Equivalent of Tailing a MongoDB Operation Log in SQL Server?

MongoDB has something called an oplog which you can tail to read/replay all operations (insert, update, delete, etc) that happen to a database. I am looking to do something similar in SQL Server but have been unable to find anything equivalent. Does anything similar to this exist in SQL Server, and more specifically, SQL Azure?
Depending on what version of SQL Server your running, I believe Change Data Capture will cover your need. There are built in functions that will allow you to query all the changes that took place on CDC enabled tables. I've included a link from the Microsoft TechNet library and another from a blog that provides an introduction to CDC.
Hope this helps!
SQL Server has the Transaction Log facility that does just that - record all transactions in order to be able to rollback up to a certain point.
As stated here you can use DBCC LOG(databasename, typeofoutput) to access that information
Easy way to accomplish it is SQL Server profiler. Other ways are given here. You can save SQL Server Profiler output to file or table then use other means to read it.

Sql Server logging tool

I'm creating a web application.
I would like to know if there is a log system for SQL Server.
Otherwise, I think I'll need to create my own table set and make all the query to insert in theses table.
Thanks.
Have a look at SQL Server Profiler. It allows you to start a trace and log all queries to a file, a table or a client. It comes with the SQL Server client installation.
Introducing SQL Server Profiler
Using SQL Server Profiler
If you are looking to track (audit) what tables are being queried (SELECT), SQL Profiler is about the only way to go.
If you are looking to audit (track) changes made to the database (INSERT, UPDATE, DELETE, and even most CREATE, ALTER, and DROPs), you may want to look at triggers and audit tables. There may be third-party tools out there that do this, SQL 2008 has a feature that can also do this for you (I haven't used it, don't yet need it, and can't quickly find it in BOL, but I know it's there), or you can just implement your own--do some searches for "audit tables" and triggers and you'll find loads of examples out there.
...hah, found it! Look for "Change Data Capture", available only in SQL 2008 Enterprise edition.

How to query from log files (.ldf) of Sql Server 2005 Express edition?

I want to do this, because I would like to know how many times a particular row has been changed.
Is this possible?
Thanks
Reading the log file either takes a commercial tool, or an incredible amount of SQL internals knowledge to achieve. You can see some of the raw output by using:
Select * from ::fn_DBlog(null,null)
Actually decoding to find the same record being altered and ensuring any alteration was committed etc would be a difficult task to put it lightly. So it is 'possible' but not very 'probable' that you will be able to do it.
If you need that functionality within a database then you should be looking at triggers / logic within the code.
Late answer but I hope it will be useful to new readers…
One more function you can try is DBCC LOG but unfortunately this is undocumented function same like fn_dblog.
Problem with transaction log in SQL Server is that it was never meant to be used for this but only to allow point in time recovery and transaction properties.
There is a commercial log reader from ApexSQL that you can try.
Here are also couple similar posts that might get you in the right direction.
Read the log file (*.LDF) in sql server 2008
SQL Server Transaction Log Explorer/Analyzer
you can use this program to do it
http://www.red-gate.com/products/SQL_Log_Rescue/index.htm
Consider using SQL Server 2008.
There is a feature new to SQL Server 2008 called Change Data Capture that does exactly what you require, that is to track data modifications over time.
Looking to inspect the log file in order to track changes is not a wise practice. Doing so will provide you with a limited history, the scope of which would also be dependent on the Recovery Model that you use for your database.
You could "roll your own" solution with a small amount of development, by using a log table and populating it using SQL Server Triggers. The suitability of such a solution is of course dependent on your business case.
Take a look at the following TechNet article for some interesting reading:
Tracking Changes in Your Enterprise Database

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.

Restore SQL Server 2008 database to SQL Server 2000

I have to move an entire database from a SQL Server 2008 machine to a SQL Server 2000 machine.
I created a backup using Management Studio 2008, copied it to the hard drive of the 2000 box, and from withing Management Studio 2008, I choose Restore Database to the 2000 box.
I get an error message stating, "The media family on device ... is incorrectly formed. SQL Server cannot restore this media family".
If I use Enterprise Manager 2000 I get the same error.
Is there a way to move a whole database from the newer SQL server to the older?
The only thing I can think of is to recreate the whole structure and then copy data from a live database. So, create scripts that will create the tables, views, and sp's, and then create scripts to copy the data from the existing database.
As others already said there is no default way to do this. It’s just not supported. Here are more extensive details on how to do this properly and avoid any migration issues.
You need to generate scripts for structure and data and then execute these on SQL 2000 (like others already said) but there are couple things to take into account.
Generate scripts in SSMS
Make sure to check option for scripting data for SQL 2000 to avoid issues when trying to create something like geography type column on SQL 2000.
Make sure to review execution order of scripts to avoid dependency based errors
This is a great option for small to medium size databases and requires some knowledge of SQL Server (dependencies, differences between versions and such)
Third party tools
Idea is to use third party database comparison tools such as ApexSQL Diff or Data Diff
Good side is that these will take care of script execution and differences between versions
Not so good is the fact that you’ll need to pay for these after trial ends
I’ve used these two tools successfully but you can’t go wrong with any other tool on the market. Here is a list of other tools in this category.
you can't move backups from a newer version to an older, in that case you can script your database, execute it in the 2000 box, then you can use the standard data transfer to transfer any data you want
Provided you have a network connection between the machines use SSIS. Much easier and a lot less messing around.
You can use Script Generator for your database and then select in the properties form : General-> Script for server version : SQL Server 2000.
The script generator will show you things which not compatible with your server version.
I've heard you can only do it by generating the SQL statement dump from the DB administrator tool and re-running those queries on the target older database.
You can generate a script that will recreate all the objects and transfer all the data...as long as everything in the db is valid in SQL 2000. So no ROW_NUMBER(), no PARTITION, no CTEs, no datetime2, hierarchy or several other field types, no EXECUTE AS, and lots of other goodness. Basically, there's a pretty good chance it's not possible unless your db is pretty basic.
We got a similar situation. A very low-tech but handy solution is:
backup and truncate the tables in SQL 2000.
create a LINKED server in SQL 2008, pointing to SQL 2000
run a select query at sysobjects to generate a query script for insert into LINKED SERVER.table select * from table
execute query script.

Resources