Showing posts with label updated. Show all posts
Showing posts with label updated. Show all posts

Friday, March 30, 2012

How can I report on entered and updated records

My database has many table, each table has a DateEntered (datetime), EnteredBy (nvarchar(50), LastUpdate (datetime), and LastUpdateBy (nvarachar(50). Is there an easy (ha) way to pull a list of the records that were entered and/or updated for a date range. Hopefully without a select for each table.

Maybe a tool someone knows of?

Jackxxx:

My database has many table, each table has a DateEntered (datetime), EnteredBy (nvarchar(50), LastUpdate (datetime), and LastUpdateBy (nvarachar(50). Is there an easy (ha) way to pull a list of the records that were entered and/or updated for a date range. Hopefully without a select for each table.

Maybe a tool someone knows of?

You mean without doing a SELECT on the tables? Check out some log reader tools - Red Gate has one.. perhaps there are others..but then they only have so many transactions and not your entire database..

Wednesday, March 28, 2012

how can I read a table value every minute

Hi
I was wondering if there is any function by which I can read the value in a
date field every minute or so to check to see if it has been updated.
In MS Access I would have done this using the timer function but I wonder if
there is an equivalent in MSDE.
Thanks
June
hi June,
"June Macleod" <junework@.hotmail.com> ha scritto nel messaggio
news:OrxlWq4gEHA.632@.TK2MSFTNGP12.phx.gbl...
> Hi
> I was wondering if there is any function by which I can read the value in
a
> date field every minute or so to check to see if it has been updated.
> In MS Access I would have done this using the timer function but I wonder
if
> there is an equivalent in MSDE.
>
MSDE provides access to the SQL Server Agent, a native scheduler which can
be used to execute maintanance jobs, execute Transact SQL staments, run
stored procedures...
perhaps you can use it... server side... instaead of a client timer...
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtmhttp://italy.mvps.org
DbaMgr2k ver 0.8.0 - DbaMgr ver 0.54.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
-- remove DMO to reply
|||June,
Depending on what you are up to, you might find the WAITFOR command useful.
Russell Fields
"June Macleod" <junework@.hotmail.com> wrote in message
news:OrxlWq4gEHA.632@.TK2MSFTNGP12.phx.gbl...
> Hi
> I was wondering if there is any function by which I can read the value in
a
> date field every minute or so to check to see if it has been updated.
> In MS Access I would have done this using the timer function but I wonder
if
> there is an equivalent in MSDE.
> Thanks
> June
>

Wednesday, March 7, 2012

how can I get which columns were updated in trigger on update

Hi,

I'm using sql-2005.

I want to update several columns in different tables whenever an update is happend on specific table. I have a trigger for that which update all the relevant places when it fires.

I want to do this update only if certains columns were changed, otherwise - do anything, to reduce performance.

How Can I know which columns were updated inside the trigger? The tables has many columns and only if 2 of them were changed then I need to update other tables.

Many thanks,

Nira.

use Inserted & Deleted table on your Trigger to compare wheather your action columns are updated or not.

Suppose I have table Table1 with 3 columns, Id, col1, col2, col3

if i need to find from trigger wheather col1 & col3 are updated or not,

Declare @.Col1Flag as Bit, @.Col2Flag as Bit

Select

Col1Flag = Case When Ins.Col1 <> Del.Col1 Then 1 Else 0 End Col1_Updated

,Col2Flag = Case When Ins.Col3 <> Del.Col3 Then 1 Else 0 End Col3_Updated

From Inserted as Ins

Join Deleted as Del on Ins.Id = Del.Id;

|||

Many thanks for you quick response

Though maybe there is some build-in way to do that but that's definitely a simple good way.

Thx

Sunday, February 19, 2012

How can I find out who is running dangerous queries

I recently discovered that some one (or application) updated all the
rows in the database. Looks like a query was missing a where clause.
It was probably one of the applications, but reviews of the code show
that a where clauses is always used, or so it appears. Anyway, I set
up a trigger to capture every update to a particular table that
recorded who did what and when. I created the trigger (on insert and
update) on a table and in it I use the new fn_get_sql function that
comes with SQL Server 2000 SP3. It looks like this:

----------
CREATE TRIGGER Update_Last_Modified ON [dbo].[MYTABLENAME]
FOR UPDATE, INSERT
AS
BEGIN
SET NOCOUNT ON
DBCC TRACEON (2861)

DECLARE @.Qry nvarchar(4000)

DECLARE @.handle binary(20)

SELECT @.handle = sql_handle
FROM master..sysprocesses
WHERE spid = @.@.SPID

SET @.QRY = (SELECT CONVERT(nvarchar(4000), [text]) FROM
::fn_get_sql(@.handle))

UPDATE MYTABLENAME
SET DATE_LAST_MODIFIED = GETDATE(),
LAST_COMMAND = @.QRY,
LAST_USER = SYSTEM_USER
FROM inserted
WHERE MYTABLENAME.UID= Inserted.UID
END

-----------

It was previously coded to use DBCC INPUTBUFFER, and it worked fine,
but I was limited to the first 255 characters of the command, which
prevented me from seeing the critical parts, like the where clause!
When I modified the trigger to use fn_get_sql, all I ever see is the
entire text of the create trigger command. Maybe I should use an
entirely different approach. I'm open to ideas.

Thanks very much in advance for your help!

Miles

_________________Miles (milesfeinberg@.hotmail.com) writes:
> It was previously coded to use DBCC INPUTBUFFER, and it worked fine,
> but I was limited to the first 255 characters of the command, which
> prevented me from seeing the critical parts, like the where clause!
> When I modified the trigger to use fn_get_sql, all I ever see is the
> entire text of the create trigger command. Maybe I should use an
> entirely different approach. I'm open to ideas.

Yes, the idea with fn_get_sql is to get the currently executing statement
of a procedure. And for a process that introspects itself, the current
statement will be the statement it queries sysprocesses. So in your
case DBCC INPUTBUFFER is a better bet.

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp