March 12, 2016 at 12:24 am
I need to keep history for each record in my table. I created another same structured table with action field which mentions its insert or update.Here is my structure
CREATE TABLE IF NOT EXISTS `crm_listings_history` (
`id` bigint(20) unsigned NOT NULL,
`user_id` int(11) NOT NULL,
`ref` varchar(55) NOT NULL,
`name` mediumtext NOT NULL,
`description` longtext NOT NULL,
`beds` varchar(22) NOT NULL,
`baths` int(11) NOT NULL DEFAULT '1',
`unit` varchar(55) NOT NULL,
`size` int(11) NOT NULL,
`price` decimal(18,2) NOT NULL,
`dateadded` datetime NOT NULL,
`listing_id` int(11) NOT NULL
)
Where listing_id is the id of crm_listings table.Now i want to get result like
UserID | Action | DateAdded |Field | Ref
1 | Insert | 21/05/2015 | Id | ABC
1 | Update | 21/05/2015 |Price | ABC
how i can write this query? How i can find which field has been updated?
March 12, 2016 at 3:11 am
looking at your table definition, it would seem that you are not using MS SQL...(.MySQL maybe?)
this site is for Microsoft SQL predominately ....you may find you get better answers in a forum dedicated to your database.
________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day
March 12, 2016 at 3:21 am
I just created this structure as available tool to give understanding of my question.I have to use SQL.
March 12, 2016 at 3:37 am
ok....please read
http://spaghettidba.com/2015/04/24/how-to-post-a-t-sql-question-on-a-public-forum/
then post back with create table statements, sample data and expected results as shown above.
________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day
March 12, 2016 at 7:20 am
just came across this....seems quite similar, but states MySQL
http://stackoverflow.com/questions/35917478/find-difference-between-two-records-in-mysql
________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day
March 12, 2016 at 7:46 am
The question sounds like you want to create an audit table. Like J Livingston pointed out, this is a SQL Server forum.
March 14, 2016 at 4:29 pm
It depends on what version you are using
MSSQL 2014+ has that feature:
March 14, 2016 at 5:39 pm
The Danish Dynamo (3/14/2016)
It depends on what version you are usingMSSQL 2014+ has that feature:
Here's why I don't use that feature...
•There is a built-in cleanup mechanism. Cleanup for change tracking is performed automatically in the background.
That violates the requirements placed upon me to keep audit data forever. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply