SQL Server 2016 - Auditing a view - sql-server-2016

What is the best way to audit a view? I set up an audit which outputs to a file, set up a database audit specification for select, insert, delete, update for that view for a specific user (even though I think there should only be select). I enabled the audit and it created the file. However, 24 hours later, there is nothing in that file (other than the initialization info). Is this the right way to audit a view? Thanks!

If you have Sql-Server 2016 SP1 or newer you can audit anything.

Related

How to recover deleted data from SQL server table? [duplicate]

I accidentaly ran a DELETE command against a table with a wrong WHERE
clause.
I am using SQL Server 2005.
Is there a way that could help me recover the lost data?
It is possible using Apex Recovery Tool,i have successfully recovered my table rows which i accidentally deleted
if you download the trial version it will recover only 10th row
check here http://www.apexsql.com/sql_tools_log.aspx
You have Full data + Transaction log backups, right? You can restore to another Database from backups and then sync the deleted rows back. Lots of work though...
(Have you looked at Redgate's SQL Log Rescue? Update: it's SQL Server 2000 only)
There is Log Explorer
I think thats impossible, sorry.
Thats why whenever running a delete or update you should always use BEGIN TRANSACTION, then COMMIT if successful or ROLLBACK if not.
What is gone is gone. The only protection I know of is regular backup.

Editing SQL in Triggers with code

I have been migrating a database from SQL Server 2008 to 2012 and there have been problems with triggers that contain RAISERROR, because the syntax has changed between version. Now I could go through and change all of these manually, but that is a whole days work in itself.
Ideally there is a way where I can get a program to go into the triggers and change the RAISERRORs to the new syntax, this will be useful because I will upgrading another server soon and would speed up that process as well.
I have looked into SSMS Add-ins and believe they can directly edit the code within a trigger but the documentation is sparse.
I don't believe it can be done through SQL itself they can only ALTER TRIGGER, whereas I want to actually change the code inside the trigger.

Update on table really slow in ACCESS, fast in Management Studio

There is a table with trigger in our SQL database. (sql server 2014). When updating record from Microsoft SQL Server Management Studio update takes like 1/10 sec. When the record is changed in MS ACCESS (in the form) it takes like 5-6 seconds to update. There is a trigger on that table, but the same operation directly from MSS Management Studio is fast, so it is not a problem with a trigger itself. THe trigger has to insert 1 record to 15 milion records table. I am looking for reasons why the same operation from ACCESS and SQL management studio can take 40 times longer. Any suggestions? Or links to known issues in that topic?
EDIT:
It's ACCESS 2003. It's subform bound to form by ID field. I am edditing simple integer column of record. I use normal connection with my sql server, it's adp project and we just use typical connection for it. I tried to do update from VBA (the same project) but from simple module -> the same effect. So it does not metter if it is eddited from form or update command is send from other module to that table. It still takes long.
To narrow things down I would still suggest to disable the trigger and see if the issue persists.

Avoid replicating DELETE statements in SQL Server

Consider the following scenario:
One PC is running an Access database. An old legacy script will copy over all the contents from this Access database to a SQL Server (A) over LAN. But before it does this, it will delete all contents from the destination database, so it doesn't have to deal with existing records. Previously existing records are never altered.
On the SQL Server (A), replication is defined and it acts as a publisher. It will publish/replicate the data to SQL Server (B) over WAN.
This all works very well, but the only problem I'm facing is when there's a problem during the copying of contents to SQL Server (A), SQL Server (B) will be empty or missing records, even the records that were replicated a long time ago.
There are two solutions I've already considered:
Adapt the legacy script to only copy over new records, since the updates are incremental of nature.
Configure the replication to avoid DELETE statements.
The first solution is in this scenario not possible. The application is closed-source, and there's really nothing we can change.
The second solution would be ideal, but (A) would try to replicate records that already exist on (B), and I'm not quite sure how to handle that.
Surely there's a sound concept to this problem, I just haven't figured it out yet..
In SSMS go to Replication -> Local Publications and right click on your publication and select Properties. In the Publication Properties window click on 'Articles' and select the relevant article. Go to "Article Properties" and select "Set Properties of Highlighted Table Article". In the article properties window, change the "DELETE delivery format" to "Do not replicate DELETE statements".
After the change click OK and you will see a prompt. As the article property has been changed the subscriptions need to be reinitialized. Click "Mark for Reinitialization" which causes the snapshot to be applied to the subscriber.
In SSMS, navigate to Replication and right click and select "Launch Replication Monitor". Go to your publication and click View Details to see the snapshot progress.

Undo changes to SQL Server 2005 database

I've ran some "ALTER" scripts on the database [SQL Server Server 2005], and overwrote some sprocs. Is there any way to undo changes and get my old sprocs back?
Is there a way to get the scripts that were executed out of the .LDf file? That way i can re-run my initial "create" script for my sprocs.
I don't have a backup file with old sprocs.
p.s. i backed the DB up as per #Gulzar's deleted answer, and looks like I'm "hosed".
#Pittsburgh DBA: thanx for the solution, but it doesn't seem to work after the backup.
MORAL: Wait for 10 minutes before trying the suggested answers out
Update from Gulzar: What I meant was a file backup before trying anything (to be safe). Not a SQL Server backup.
FIRST: DO NOT TAKE ANY BACKUPS JUST YET.
There are several tools on the market to do this sort of thing.
You might try this one:
ApexSQL Log
In case anybody else has the same problem - Were you doing transaction log backups every X minutes? If so, you can use Quest LiteSpeed's log reader or Quest Toad for SQL Server's log reader to read the log file backups. It gives undo/redo scripts too for any transaction in the log backups or the ldf.
And after that, look into using ApexSQLScript to script out your databases on a regular basis (and store in version control).
yo do can!!
go to sql server managment studio,connect to your db, left click on your db and go to "tasks".
select restore -> database.
then click the "timeline" button and select 'especific date' and select the day before your mistake.
All programs that have access to your db mus be closed.
It worked for me, i had this very same probelm.