Showing posts with label track. Show all posts
Showing posts with label track. Show all posts

Friday, February 24, 2012

How to combine 2 records into 1 unique record

Hi all,

We have an app that uses SQL 2000. I am trying to track when a code field
(selcode) is changed on an order which then causes a status field (status)
to change. I tried a trigger but the app may use 2 different update
statements to change these fields depending on what the user does. When the
trigger fires (on update to selcode), the status field has already been
changed. So my trigger to record the changes from inserted and deleted do
not get the true 'before' value of the status field.

The app does use a log table that tracks these changes. The problem I am
having is that 2 records are created, one for the change to selcode and
another for the change to status.

I am looking for help with a script to combine the existence of these 2 log
records into 1 unique record or occurance that I can track.

example:
ordlog: table that logs order changes
ordernr: order number
varname: name of field being changed
old_value: contents of field before change
new_value: contents of field after change
syscreated: date/time of log entry

SELECT ordernr, varname, old_value, new_value, syscreated
FROM ordlog
where varname = 'selcode' and ordernr = '10580'

SELECT ordernr, varname, old_value, new_value, syscreated
FROM ordlog
where varname = 'status' and ordernr = '10580' and old_value = 'A' and
new_value = 'O'

So I need a way to combine these 2 log entries into a unique occurance. The
ordernr and syscreated could be used to link records. syscreated always
appears to be the same for the 2 log entries down to the second. Selcode
can change from NULL to a number of different values or back to NULL.Status
is either 'A' for approved or 'O' for open. An order can have many log
entries during its life. The selcode may be changed several times for the
same order.

Ideally, I would like a result that links 2 log entries and shows the status
changed from 'A' to 'O' when selcode changed.

Thanks for your time.rdraider (rdraider@.sbcglobal.net) writes:

Quote:

Originally Posted by

SELECT ordernr, varname, old_value, new_value, syscreated
FROM ordlog
where varname = 'selcode' and ordernr = '10580'
>
>
SELECT ordernr, varname, old_value, new_value, syscreated
FROM ordlog
where varname = 'status' and ordernr = '10580' and old_value = 'A' and
new_value = 'O'
>
>
So I need a way to combine these 2 log entries into a unique occurance.
The ordernr and syscreated could be used to link records. syscreated
always appears to be the same for the 2 log entries down to the second.
Selcode can change from NULL to a number of different values or back to
NULL.Status is either 'A' for approved or 'O' for open. An order can
have many log entries during its life. The selcode may be changed
several times for the same order.
>
Ideally, I would like a result that links 2 log entries and shows the
status changed from 'A' to 'O' when selcode changed.


Could this do:

SELECT a.ordernr, a.syscreated,
oldselcode = a.old_value, newselcode = a.new_value,
oldstatus = b.old_value, newstatus = b.new_value
FROM ordlog a
JOIN ordlog b ON a.ordernr = b.ordernr
AND datediff(seconds, a.syscreated, b.syscreated) <= 1
WHERE a.varname = 'selcode'
AND b.varname = 'status'
AND coalesce(a.old_value, '') <coalesce(a.new_value, '')
AND a.old_value = 'A'
AND b.new_value = 'B'

Note: this is an untested query.

If the does not return the expected results, I suggest that you post:

o CREATE TABLE statments for the involved table(s).
o INSERT statements with sample data.
o The desired output given the sample.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

Sunday, February 19, 2012

How to clear the log (ldf) file?

Hi all.
I have a database I need no auditor to be able to track changes made to it.
As far as I know, the LDF file keeps a record of all the transactions
performed on it which is exactly what I dont want. I've read that it is
impossible to disable logging in MSSQL. Is this 100% true? Has anyone found a
way to keep the logs file clear?
Att,
RODOLFO
Yes, you are right that we cannot "disable"logging in the SQL Server.
If you want to let to SQL Server to manage its LOG file in terms of size ,
so set the recovery model to SIMPLE
For more info please refer to the BOL
"RODOLFO" <RODOLFO@.discussions.microsoft.com> wrote in message
news:99344364-41EF-46BB-A7F2-6621D7944A51@.microsoft.com...
> Hi all.
> I have a database I need no auditor to be able to track changes made to
it.
> As far as I know, the LDF file keeps a record of all the transactions
> performed on it which is exactly what I dont want. I've read that it is
> impossible to disable logging in MSSQL. Is this 100% true? Has anyone
found a
> way to keep the logs file clear?
> Att,
> RODOLFO
|||Hi,
We can not totally stop loggin in sql server.
But if you select the RECOVERY model for your database as SIMPLE then
transaction log will be cleared automatically
Has anyone found a way to keep the logs file clear?
If it is SIMPLE recovery log will be cleared automatically, but for other
recovery model you need to perform the transaction log backup.
See Backup Log command in books online.
Thanks
Hari
SQL Server MVP
"RODOLFO" <RODOLFO@.discussions.microsoft.com> wrote in message
news:99344364-41EF-46BB-A7F2-6621D7944A51@.microsoft.com...
> Hi all.
> I have a database I need no auditor to be able to track changes made to
> it.
> As far as I know, the LDF file keeps a record of all the transactions
> performed on it which is exactly what I dont want. I've read that it is
> impossible to disable logging in MSSQL. Is this 100% true? Has anyone
> found a
> way to keep the logs file clear?
> Att,
> RODOLFO
|||To add to the other responses, the transaction log is required in order to
maintain database consistency. This is used by SQL Server to guarantee
all-or-nothing atomic transactions. Although the log can be used by
third-party tools for auditing purposes, the primary purpose of the log is
to facilitate the backout and roll-forward of transactions.
You can keep transaction log file size reasonable by choosing the
appropriate recovery model and backup strategy for your environment.
Hope this helps.
Dan Guzman
SQL Server MVP
"RODOLFO" <RODOLFO@.discussions.microsoft.com> wrote in message
news:99344364-41EF-46BB-A7F2-6621D7944A51@.microsoft.com...
> Hi all.
> I have a database I need no auditor to be able to track changes made to
> it.
> As far as I know, the LDF file keeps a record of all the transactions
> performed on it which is exactly what I dont want. I've read that it is
> impossible to disable logging in MSSQL. Is this 100% true? Has anyone
> found a
> way to keep the logs file clear?
> Att,
> RODOLFO
|||Hello and thanks a lot for your answers.
I think I understand better the purpose of the log file now reading your
posts. The problem is that it just confirms my fears. I need NO ONE to be
able to perform an audit on this database. The ideal situation will be to
disable this logging. Now I know it can't be done in MS SQL... what's the
closest to it I can get?
Att,
RODOLFO
"Dan Guzman" wrote:

> To add to the other responses, the transaction log is required in order to
> maintain database consistency. This is used by SQL Server to guarantee
> all-or-nothing atomic transactions. Although the log can be used by
> third-party tools for auditing purposes, the primary purpose of the log is
> to facilitate the backout and roll-forward of transactions.
> You can keep transaction log file size reasonable by choosing the
> appropriate recovery model and backup strategy for your environment.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "RODOLFO" <RODOLFO@.discussions.microsoft.com> wrote in message
> news:99344364-41EF-46BB-A7F2-6621D7944A51@.microsoft.com...
>
>
|||If you don't want anyone to read the log then don't give them permissions to
that folder. The physical security of the data files is up to you at the
Windows level.
Andrew J. Kelly SQL MVP
"RODOLFO" <RODOLFO@.discussions.microsoft.com> wrote in message
news:634187D5-A399-4B4A-85D4-3CA9C7FF62B0@.microsoft.com...[vbcol=seagreen]
> Hello and thanks a lot for your answers.
> I think I understand better the purpose of the log file now reading your
> posts. The problem is that it just confirms my fears. I need NO ONE to be
> able to perform an audit on this database. The ideal situation will be to
> disable this logging. Now I know it can't be done in MS SQL... what's the
> closest to it I can get?
> Att,
> RODOLFO
> "Dan Guzman" wrote:

How to clear the log (ldf) file?

Hi all.
I have a database I need no auditor to be able to track changes made to it.
As far as I know, the LDF file keeps a record of all the transactions
performed on it which is exactly what I dont want. I've read that it is
impossible to disable logging in MSSQL. Is this 100% true? Has anyone found
a
way to keep the logs file clear?
Att,
RODOLFOYes, you are right that we cannot "disable"logging in the SQL Server.
If you want to let to SQL Server to manage its LOG file in terms of size ,
so set the recovery model to SIMPLE
For more info please refer to the BOL
"RODOLFO" <RODOLFO@.discussions.microsoft.com> wrote in message
news:99344364-41EF-46BB-A7F2-6621D7944A51@.microsoft.com...
> Hi all.
> I have a database I need no auditor to be able to track changes made to
it.
> As far as I know, the LDF file keeps a record of all the transactions
> performed on it which is exactly what I dont want. I've read that it is
> impossible to disable logging in MSSQL. Is this 100% true? Has anyone
found a
> way to keep the logs file clear?
> Att,
> RODOLFO|||Hi,
We can not totally stop loggin in sql server.
But if you select the RECOVERY model for your database as SIMPLE then
transaction log will be cleared automatically
Has anyone found a way to keep the logs file clear?
If it is SIMPLE recovery log will be cleared automatically, but for other
recovery model you need to perform the transaction log backup.
See Backup Log command in books online.
Thanks
Hari
SQL Server MVP
"RODOLFO" <RODOLFO@.discussions.microsoft.com> wrote in message
news:99344364-41EF-46BB-A7F2-6621D7944A51@.microsoft.com...
> Hi all.
> I have a database I need no auditor to be able to track changes made to
> it.
> As far as I know, the LDF file keeps a record of all the transactions
> performed on it which is exactly what I dont want. I've read that it is
> impossible to disable logging in MSSQL. Is this 100% true? Has anyone
> found a
> way to keep the logs file clear?
> Att,
> RODOLFO|||To add to the other responses, the transaction log is required in order to
maintain database consistency. This is used by SQL Server to guarantee
all-or-nothing atomic transactions. Although the log can be used by
third-party tools for auditing purposes, the primary purpose of the log is
to facilitate the backout and roll-forward of transactions.
You can keep transaction log file size reasonable by choosing the
appropriate recovery model and backup strategy for your environment.
Hope this helps.
Dan Guzman
SQL Server MVP
"RODOLFO" <RODOLFO@.discussions.microsoft.com> wrote in message
news:99344364-41EF-46BB-A7F2-6621D7944A51@.microsoft.com...
> Hi all.
> I have a database I need no auditor to be able to track changes made to
> it.
> As far as I know, the LDF file keeps a record of all the transactions
> performed on it which is exactly what I dont want. I've read that it is
> impossible to disable logging in MSSQL. Is this 100% true? Has anyone
> found a
> way to keep the logs file clear?
> Att,
> RODOLFO|||Hello and thanks a lot for your answers.
I think I understand better the purpose of the log file now reading your
posts. The problem is that it just confirms my fears. I need NO ONE to be
able to perform an audit on this database. The ideal situation will be to
disable this logging. Now I know it can't be done in MS SQL... what's the
closest to it I can get?
Att,
RODOLFO
"Dan Guzman" wrote:

> To add to the other responses, the transaction log is required in order to
> maintain database consistency. This is used by SQL Server to guarantee
> all-or-nothing atomic transactions. Although the log can be used by
> third-party tools for auditing purposes, the primary purpose of the log is
> to facilitate the backout and roll-forward of transactions.
> You can keep transaction log file size reasonable by choosing the
> appropriate recovery model and backup strategy for your environment.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "RODOLFO" <RODOLFO@.discussions.microsoft.com> wrote in message
> news:99344364-41EF-46BB-A7F2-6621D7944A51@.microsoft.com...
>
>|||If you don't want anyone to read the log then don't give them permissions to
that folder. The physical security of the data files is up to you at the
Windows level.
Andrew J. Kelly SQL MVP
"RODOLFO" <RODOLFO@.discussions.microsoft.com> wrote in message
news:634187D5-A399-4B4A-85D4-3CA9C7FF62B0@.microsoft.com...[vbcol=seagreen]
> Hello and thanks a lot for your answers.
> I think I understand better the purpose of the log file now reading your
> posts. The problem is that it just confirms my fears. I need NO ONE to be
> able to perform an audit on this database. The ideal situation will be to
> disable this logging. Now I know it can't be done in MS SQL... what's the
> closest to it I can get?
> Att,
> RODOLFO
> "Dan Guzman" wrote:
>

How to clear the log (ldf) file?

Hi all.
I have a database I need no auditor to be able to track changes made to it.
As far as I know, the LDF file keeps a record of all the transactions
performed on it which is exactly what I dont want. I've read that it is
impossible to disable logging in MSSQL. Is this 100% true? Has anyone found a
way to keep the logs file clear?
Att,
RODOLFOYes, you are right that we cannot "disable"logging in the SQL Server.
If you want to let to SQL Server to manage its LOG file in terms of size ,
so set the recovery model to SIMPLE
For more info please refer to the BOL
"RODOLFO" <RODOLFO@.discussions.microsoft.com> wrote in message
news:99344364-41EF-46BB-A7F2-6621D7944A51@.microsoft.com...
> Hi all.
> I have a database I need no auditor to be able to track changes made to
it.
> As far as I know, the LDF file keeps a record of all the transactions
> performed on it which is exactly what I dont want. I've read that it is
> impossible to disable logging in MSSQL. Is this 100% true? Has anyone
found a
> way to keep the logs file clear?
> Att,
> RODOLFO|||Hi,
We can not totally stop loggin in sql server.
But if you select the RECOVERY model for your database as SIMPLE then
transaction log will be cleared automatically
Has anyone found a way to keep the logs file clear?
If it is SIMPLE recovery log will be cleared automatically, but for other
recovery model you need to perform the transaction log backup.
See Backup Log command in books online.
Thanks
Hari
SQL Server MVP
"RODOLFO" <RODOLFO@.discussions.microsoft.com> wrote in message
news:99344364-41EF-46BB-A7F2-6621D7944A51@.microsoft.com...
> Hi all.
> I have a database I need no auditor to be able to track changes made to
> it.
> As far as I know, the LDF file keeps a record of all the transactions
> performed on it which is exactly what I dont want. I've read that it is
> impossible to disable logging in MSSQL. Is this 100% true? Has anyone
> found a
> way to keep the logs file clear?
> Att,
> RODOLFO|||To add to the other responses, the transaction log is required in order to
maintain database consistency. This is used by SQL Server to guarantee
all-or-nothing atomic transactions. Although the log can be used by
third-party tools for auditing purposes, the primary purpose of the log is
to facilitate the backout and roll-forward of transactions.
You can keep transaction log file size reasonable by choosing the
appropriate recovery model and backup strategy for your environment.
--
Hope this helps.
Dan Guzman
SQL Server MVP
"RODOLFO" <RODOLFO@.discussions.microsoft.com> wrote in message
news:99344364-41EF-46BB-A7F2-6621D7944A51@.microsoft.com...
> Hi all.
> I have a database I need no auditor to be able to track changes made to
> it.
> As far as I know, the LDF file keeps a record of all the transactions
> performed on it which is exactly what I dont want. I've read that it is
> impossible to disable logging in MSSQL. Is this 100% true? Has anyone
> found a
> way to keep the logs file clear?
> Att,
> RODOLFO|||Hello and thanks a lot for your answers.
I think I understand better the purpose of the log file now reading your
posts. The problem is that it just confirms my fears. I need NO ONE to be
able to perform an audit on this database. The ideal situation will be to
disable this logging. Now I know it can't be done in MS SQL... what's the
closest to it I can get?
Att,
RODOLFO
"Dan Guzman" wrote:
> To add to the other responses, the transaction log is required in order to
> maintain database consistency. This is used by SQL Server to guarantee
> all-or-nothing atomic transactions. Although the log can be used by
> third-party tools for auditing purposes, the primary purpose of the log is
> to facilitate the backout and roll-forward of transactions.
> You can keep transaction log file size reasonable by choosing the
> appropriate recovery model and backup strategy for your environment.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "RODOLFO" <RODOLFO@.discussions.microsoft.com> wrote in message
> news:99344364-41EF-46BB-A7F2-6621D7944A51@.microsoft.com...
> > Hi all.
> > I have a database I need no auditor to be able to track changes made to
> > it.
> > As far as I know, the LDF file keeps a record of all the transactions
> > performed on it which is exactly what I dont want. I've read that it is
> > impossible to disable logging in MSSQL. Is this 100% true? Has anyone
> > found a
> > way to keep the logs file clear?
> >
> > Att,
> > RODOLFO
>
>|||If you don't want anyone to read the log then don't give them permissions to
that folder. The physical security of the data files is up to you at the
Windows level.
--
Andrew J. Kelly SQL MVP
"RODOLFO" <RODOLFO@.discussions.microsoft.com> wrote in message
news:634187D5-A399-4B4A-85D4-3CA9C7FF62B0@.microsoft.com...
> Hello and thanks a lot for your answers.
> I think I understand better the purpose of the log file now reading your
> posts. The problem is that it just confirms my fears. I need NO ONE to be
> able to perform an audit on this database. The ideal situation will be to
> disable this logging. Now I know it can't be done in MS SQL... what's the
> closest to it I can get?
> Att,
> RODOLFO
> "Dan Guzman" wrote:
>> To add to the other responses, the transaction log is required in order
>> to
>> maintain database consistency. This is used by SQL Server to guarantee
>> all-or-nothing atomic transactions. Although the log can be used by
>> third-party tools for auditing purposes, the primary purpose of the log
>> is
>> to facilitate the backout and roll-forward of transactions.
>> You can keep transaction log file size reasonable by choosing the
>> appropriate recovery model and backup strategy for your environment.
>> --
>> Hope this helps.
>> Dan Guzman
>> SQL Server MVP
>> "RODOLFO" <RODOLFO@.discussions.microsoft.com> wrote in message
>> news:99344364-41EF-46BB-A7F2-6621D7944A51@.microsoft.com...
>> > Hi all.
>> > I have a database I need no auditor to be able to track changes made to
>> > it.
>> > As far as I know, the LDF file keeps a record of all the transactions
>> > performed on it which is exactly what I dont want. I've read that it is
>> > impossible to disable logging in MSSQL. Is this 100% true? Has anyone
>> > found a
>> > way to keep the logs file clear?
>> >
>> > Att,
>> > RODOLFO
>>