Retrospective Tracking of Manual Table Editing in SQL Server - sql-server

Is there anyway to retrospectively determine if a table (or rows/fields) have been manually edited in SQL Server 2016.
Yup, you read that right. I'm trying to unravel some inconsistent data on a production database. Based on my interactions with the user and analysis of the table in question (sequential IDs don't make sense, LastUpdateDate fields inconsistent, etc.), I suspect that the table was manually edited.
Yup, it's the production database.
I appreciate that I won't be able to get what fields have changed but if I can show that the user HAS manually edited the table/database, we can work to resolve the situation.

Related

What can cause SSMA - Empty tables in SQL without error?

When I migrate from Access 2003 to SQL server 2019, I get half of the tables empty. What can cause this problem and how to fix this? Tables are not empty in Access.
Ok, so at least SOME tables are going to sql server. This is good, as it shows at least you have "some" of this working.
The tables that don't go? Often this is for two reasons.
the table(s) have bad dates - but SSMAA should spit out a error in that regards.
the other issue is if the table(s) in question have mutli-value fields (attachemnts, or a multi-select type of column. those columns are NOT supported and SQL server has no such data types, so they can't be migrated.
So, you might want to take a look at the offending table, see if any lookup-ups are defined for some of the fields (you can while in design mode - click on the lookup tab - see if a query exists). So, you need to un-convert such tables.
So, in the lookup tab, you see this:
So, as a general rule, you have to remove those columns. but, they are in fact a "hidden" table and relationship. So, in general you have to create a new child table, and fill out the related data BEFORE you migrate such data.

Is this an appropriate database design if I wanted to audit my table?

It's my first time creating an audit log for a PoS WPF application and was wondering on how exactly do I implement an auditing system because it seems like each option available has its ups and downs. So far from reading numerous articles/threads, I've narrowed down a few common practices on audit logs:
1. Triggers - Unfortunately, due to the nature of my app, I can't make use of triggers as it has no way of knowing which user has done the action. So what I did instead was to create a Stored Procedure which will handle the customer insert along with the customer log insert and its details. The Customer_Id will be provided by the application when using the Stored Procedure.
2. Have an old and new value - My initial plan was to only include the latter since I can reference its old value with the new value from the row before it but storing the the old and new value seemed more sensible, complexity-wise.
3. Use a separate database for the log / 4. Foreign Keys - This is probably my main concern, if I decide to use a separate database for the audit table, then I couldn't setup foreign keys for the customer and employee involved.
I created a mock-up erd with a master-detail table result to be shown on the wpf app to display the log to an admin and would really like your thoughts on possible problems that may arise (There's also an employee table but I forgot to put it):
https://ibb.co/dheaNK
Here's a few info that might be of help:
The database will reside together with the wpf app, which is a single computer.
The amount of customers will be less than 1000.
The amount of regular employees will be 3.
The amount of admins will be 2.
You can enable CDC Change Data Capture on SQL Server database for a specific table
This will enable you to collect all data changes on the database table logged in special tables.
You can also refer to official documents too
Here is a list of DML commands and how data changes are logged in the CDC table created for the source database table
What is good about CDC is it comes default with SQL Server and you don't have to do anything for logging. The only requirement is SQL Server Agent should be running so that the changes can be reflected on log table.

InfoPath 2010: Query data from SQL Server but limit update to two columns

Found out I have this wonderful software on my PC after working here for almost 3 years :)
So, with that said, I am a complete newbie at this. I can do the basics, which is mostly all I'll need to do with what I'm looking for, except I haven't seen how to do what I want.
What I want to do is query a SQL Server 2008 database table, gather specific data, but have end users only be able to update 2 columns of the data.
Example:
http://i.imgur.com/PfkouWn.png?1
In the above image, I want the highlighted columns to be editable to the database and the others set as read-only.
If I right click on the columns and edit the Text Box properties, there's an option in the Display tab called 'Read-only', which is probably what I'm looking for...right?
http://i.imgur.com/EleWfeP.png?1
I guess my question is, am I on the right track here? Do I create a general user in SQL Server that can read and write to the table and it will work?
Yes you are on the right track. All those fields that you don't want changed need to be marked as read only.
As for SQL Server users, you may be better off creating a Role and setting the permissions on that role. Then add your users to that role.

How do I log every data change that has been made in SQL Server?

I have a profile page (less than 10k users) and I need to track every change and update that is made through out the application, by the users. Whether a user updates the profile picture or adds an extra space in a "comments" field, I need to store the previous data.
In short: I need to store everything.
Is there some sort of "tracking-history-and-changes-in-sql-server" software or do I have to implement it myself?
If I have to implement it myself I can think of three ways to do it:
I keep everything in the same table
but I add a key column that
specifies which row is active
and which is old.
I add a new table called history
where I store the column name that had the
change, when it was changed and what
the old data was.
I add a history table for each table
in the database. It looks the same
but only keep track of each tables
history.
Has anyone had a similar problem and how did you solve it?
This was built using mvc 4 and it's a
normal website.
EDIT
I'm mostly interested in existing solutions/software, but If there are none I would have to do it myself.
Has anyone used SQL Data Compare?
Where I worked last everything had to be logged fully. (working with goverment organisations). We never updated or deleted data.
What you would do is have a start date and an end date on each row. To do an update you would update the old data to have an enddate then insert a new row in the table. To do a delete you would put an enddate on the row with a null enddate. We also had an "updated by" column to put the userid
I used the third approach to do that but didn't create a history table for all tables of my DB but history tables for most important tables. You can use triggers to do that , create trigger for Update. You can read more about Triggers here and here
Microsoft offers Change Tracking and Change Data Capture for awhile now. These technically offer the tracking of all your changes in your database, which suits your purpose. Just note that CT is available in most versions, whereas CDC used to be only available in Enterprise until SQL Server 2016, where they made it available for Standard too.
ApexSQL Log does pretty much the same as well, but if you're using SQL Server then it's integrated in your software already.
have you considered enabling full transaction logging on your database and then using some of the log reading tools to monitor data changes. ApexSQL Log is by far the best log reader on the market but there are other solutions out there. SQL Log Rescue from Red Gate is free but it's only for sql server 2000.
Using this approach you dont need to make any other changes in your database or in your application since every transaction is automatically logged when database is in full recovery mode.
Hope this helps.

Performing Calculations in a table's field with Transactions Table

One thing I want to do is build a personal database for myself at home to use a financial database (transaction log, checking/savings account tables, etc), and I want to do this mainly to learn more about developing databases. I am pretty familiar with MS Access, though not put to use in this context, but what I am really trying to learn is SQL Server.
SO, that being said, the first question that popped into my mind is that if I have a transactions table that I would want to use as a ledger, then is there some method to have the table automatically perform a calculation for one field (balance) based on another field(s) (expense, revenue fields)? Similar to what someone may do with Excel......
Or is this something I would have to do with an unbound form, and an UPDATE statement kinda of approach? If a table constraint exists for this type of idea, I would like to learn it....
I mentioned MS Access in the title, but a SQL Server is also most appreciated. Thanks for the help!
Derived data should not be stored except if it needs to be indexed -- you calculate the values in your SQL statements, or in the presentation layer.
In addition to computed columns in SQL Server tables, you can have them in VIEWS and you can index them. The term is "indexed view" and when you do that, the data is persisted in a hidden temp table and updated on the fly when the data the VIEW is derived from is changed. You can read about it under the TYPES OF VIEWS topic in the same link cited in #Roland Bouman's answer.
Last of all, it's not clear to me why you mention Access at all if you're using SQL Server as your back end. Are you developing your front end in Access?
In MS SQL server, you can use computed columns for this: http://msdn.microsoft.com/en-us/library/ms191250.aspx

Resources