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

Wednesday, March 7, 2012

How is sysindexes.rows updated by SQL Server?

I know that the rows column on sysindexes is not always accurate, and
that I can force and update by using DBCC UPDATEUSAGE, but I'm
wondering what happens "behind the scenes" so that this value is
eventually updated with the correct value.
The particular example that I'm working with is this: a developer
noticed that the rows property on the table pop-up in EM doesn't match
the actual row count. I explained to him why the values didn't match,
but I have to believe that eventually this value will be changed and
EM will report the accurate row count. Is this correct?
Thanks in advance!
Maria
One thing that corrects the value is DBCC CHECKDB (which I assume that you run regularly).
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"Maria Vogel" <vogelm@.meijer.com> wrote in message news:1715eae1.0405110654.460c627@.posting.google.co m...
> I know that the rows column on sysindexes is not always accurate, and
> that I can force and update by using DBCC UPDATEUSAGE, but I'm
> wondering what happens "behind the scenes" so that this value is
> eventually updated with the correct value.
> The particular example that I'm working with is this: a developer
> noticed that the rows property on the table pop-up in EM doesn't match
> the actual row count. I explained to him why the values didn't match,
> but I have to believe that eventually this value will be changed and
> EM will report the accurate row count. Is this correct?
> Thanks in advance!
> Maria
|||Tibor, no it doesn't. Only DBCC UPDATEUSAGE does it.
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:evWisr$NEHA.3596@.tk2msftngp13.phx.gbl...
> One thing that corrects the value is DBCC CHECKDB (which I assume that you
run regularly).
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
>
> "Maria Vogel" <vogelm@.meijer.com> wrote in message
news:1715eae1.0405110654.460c627@.posting.google.co m...
>
|||Ahh, thanks Paul. I didn't know that was changed since the old days (I still recall 6.5, where only way to
adjust space allocation for syslogs was through CHECKDB...). :-)
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"Paul S Randal [MS]" <prandal@.online.microsoft.com> wrote in message
news:%23OrDTGFOEHA.1104@.TK2MSFTNGP10.phx.gbl...
> Tibor, no it doesn't. Only DBCC UPDATEUSAGE does it.
> --
> Paul Randal
> Dev Lead, Microsoft SQL Server Storage Engine
> This posting is provided "AS IS" with no warranties, and confers no rights.
> "Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
> message news:evWisr$NEHA.3596@.tk2msftngp13.phx.gbl...
> run regularly).
> news:1715eae1.0405110654.460c627@.posting.google.co m...
>

How is sysindexes.rows updated by SQL Server?

I know that the rows column on sysindexes is not always accurate, and
that I can force and update by using DBCC UPDATEUSAGE, but I'm
wondering what happens "behind the scenes" so that this value is
eventually updated with the correct value.
The particular example that I'm working with is this: a developer
noticed that the rows property on the table pop-up in EM doesn't match
the actual row count. I explained to him why the values didn't match,
but I have to believe that eventually this value will be changed and
EM will report the accurate row count. Is this correct?
Thanks in advance!
MariaOne thing that corrects the value is DBCC CHECKDB (which I assume that you r
un regularly).
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"Maria Vogel" <vogelm@.meijer.com> wrote in message news:1715eae1.0405110654.460c627@.posting.
google.com...
> I know that the rows column on sysindexes is not always accurate, and
> that I can force and update by using DBCC UPDATEUSAGE, but I'm
> wondering what happens "behind the scenes" so that this value is
> eventually updated with the correct value.
> The particular example that I'm working with is this: a developer
> noticed that the rows property on the table pop-up in EM doesn't match
> the actual row count. I explained to him why the values didn't match,
> but I have to believe that eventually this value will be changed and
> EM will report the accurate row count. Is this correct?
> Thanks in advance!
> Maria|||Tibor, no it doesn't. Only DBCC UPDATEUSAGE does it.
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:evWisr$NEHA.3596@.tk2msftngp13.phx.gbl...
> One thing that corrects the value is DBCC CHECKDB (which I assume that you
run regularly).
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
>
> "Maria Vogel" <vogelm@.meijer.com> wrote in message
news:1715eae1.0405110654.460c627@.posting.google.com...
>|||Ahh, thanks Paul. I didn't know that was changed since the old days (I still
recall 6.5, where only way to
adjust space allocation for syslogs was through CHECKDB...). :-)
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"Paul S Randal [MS]" <prandal@.online.microsoft.com> wrote in message
news:%23OrDTGFOEHA.1104@.TK2MSFTNGP10.phx.gbl...
> Tibor, no it doesn't. Only DBCC UPDATEUSAGE does it.
> --
> Paul Randal
> Dev Lead, Microsoft SQL Server Storage Engine
> This posting is provided "AS IS" with no warranties, and confers no rights
.
> "Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote i
n
> message news:evWisr$NEHA.3596@.tk2msftngp13.phx.gbl...
> run regularly).
> news:1715eae1.0405110654.460c627@.posting.google.com...
>

How is sysindexes.rows updated by SQL Server?

I know that the rows column on sysindexes is not always accurate, and
that I can force and update by using DBCC UPDATEUSAGE, but I'm
wondering what happens "behind the scenes" so that this value is
eventually updated with the correct value.
The particular example that I'm working with is this: a developer
noticed that the rows property on the table pop-up in EM doesn't match
the actual row count. I explained to him why the values didn't match,
but I have to believe that eventually this value will be changed and
EM will report the accurate row count. Is this correct?
Thanks in advance!
MariaOne thing that corrects the value is DBCC CHECKDB (which I assume that you run regularly).
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"Maria Vogel" <vogelm@.meijer.com> wrote in message news:1715eae1.0405110654.460c627@.posting.google.com...
> I know that the rows column on sysindexes is not always accurate, and
> that I can force and update by using DBCC UPDATEUSAGE, but I'm
> wondering what happens "behind the scenes" so that this value is
> eventually updated with the correct value.
> The particular example that I'm working with is this: a developer
> noticed that the rows property on the table pop-up in EM doesn't match
> the actual row count. I explained to him why the values didn't match,
> but I have to believe that eventually this value will be changed and
> EM will report the accurate row count. Is this correct?
> Thanks in advance!
> Maria|||Tibor, no it doesn't. Only DBCC UPDATEUSAGE does it.
--
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:evWisr$NEHA.3596@.tk2msftngp13.phx.gbl...
> One thing that corrects the value is DBCC CHECKDB (which I assume that you
run regularly).
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
>
> "Maria Vogel" <vogelm@.meijer.com> wrote in message
news:1715eae1.0405110654.460c627@.posting.google.com...
> > I know that the rows column on sysindexes is not always accurate, and
> > that I can force and update by using DBCC UPDATEUSAGE, but I'm
> > wondering what happens "behind the scenes" so that this value is
> > eventually updated with the correct value.
> >
> > The particular example that I'm working with is this: a developer
> > noticed that the rows property on the table pop-up in EM doesn't match
> > the actual row count. I explained to him why the values didn't match,
> > but I have to believe that eventually this value will be changed and
> > EM will report the accurate row count. Is this correct?
> >
> > Thanks in advance!
> > Maria
>|||Ahh, thanks Paul. I didn't know that was changed since the old days (I still recall 6.5, where only way to
adjust space allocation for syslogs was through CHECKDB...). :-)
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"Paul S Randal [MS]" <prandal@.online.microsoft.com> wrote in message
news:%23OrDTGFOEHA.1104@.TK2MSFTNGP10.phx.gbl...
> Tibor, no it doesn't. Only DBCC UPDATEUSAGE does it.
> --
> Paul Randal
> Dev Lead, Microsoft SQL Server Storage Engine
> This posting is provided "AS IS" with no warranties, and confers no rights.
> "Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
> message news:evWisr$NEHA.3596@.tk2msftngp13.phx.gbl...
> > One thing that corrects the value is DBCC CHECKDB (which I assume that you
> run regularly).
> >
> > --
> > Tibor Karaszi, SQL Server MVP
> > http://www.karaszi.com/sqlserver/default.asp
> >
> >
> > "Maria Vogel" <vogelm@.meijer.com> wrote in message
> news:1715eae1.0405110654.460c627@.posting.google.com...
> > > I know that the rows column on sysindexes is not always accurate, and
> > > that I can force and update by using DBCC UPDATEUSAGE, but I'm
> > > wondering what happens "behind the scenes" so that this value is
> > > eventually updated with the correct value.
> > >
> > > The particular example that I'm working with is this: a developer
> > > noticed that the rows property on the table pop-up in EM doesn't match
> > > the actual row count. I explained to him why the values didn't match,
> > > but I have to believe that eventually this value will be changed and
> > > EM will report the accurate row count. Is this correct?
> > >
> > > Thanks in advance!
> > > Maria
> >
> >
>

How is represented the Updated Table in a Trigger?

Hello

I am a newbie creating triggers and I would like to know what is the name of the updated logical table. That is, since the are identifiers like "inserted" and "deleted" that represent the inserted and deleted rows, respectivaly, I presumed that "updated" existed - but it does not.

I have a table with a column named "UpdatedTimeStamp" which I would like to update anytime the other columns are modified. I intended to create the following trigger:

create trigger myTrigger
on myTable
after update
as

update updated set UpdateTimeStamp=GetDate()

Of course, "updated" is not a valid identifier that represents the updated row.

Please, help me in creating this trigger. What is the correct way of doing a trigger like this?

Thanks a lot in advanced.Do you have books online?

Its inerted and deleted|||I know, but as I stated in my previous post, I do not know how to update a row which has just been updated. For example: I have a table with 2 columns, A and B -where B is a datetime column. I would like that when A has just been updated (not inserted or deleted), B would have the datetime value when that happened. Something like:

update [updated] set B=GetDate()

Of course, [updated] is not valid identifier for a logical table. Can you please help me in how to accomplish this scenary?|||The way you tell a row or rows have been updated is that both the inserted and deleted tables contain data. On an insert, the data only appears in the inserted table. On a delete, the data only appears in the deleted table.

Now with this information, try and put together a trigger for an update, and come back with your results. Also, you might want to include some schema information, so we can see the table or tables you are trying to maintain.

And remember, you want the trigger to update all rows updated, not just one of them. Think about set based operations.|||Do you have books online?

Its inerted :shocked: and deleted

How long have you been working in the bomb disposal unit at your office?

:D

hmscott|||I came up with the following solution:

suppose the existence of a table called myTable, having the columns:
- ID numeric (PK)
- Value varchar(50)
- UpdateTimeStamp datetime

Now, my trigger is

create trigger myTrigger
on myTable
after update
as

if update(Value)
begin
update myTable
set
UpdateTimeStamp=GetDate()
from myTable
inner join inserted i on i.ID=myTable.ID
inner join deleted d on d.ID=myTable.ID
end

Is this code ok?

If I open the table and modify a row, the UpdateTimeStamp column is updated as expected. However, when I update only some rows with a query, for a reason I failed to understand, all the rows get their UpdateTimeStamp field updated.

What could be wrong?|||Personally, I would not bother with the UPDATE() function. It can be misleading, especially when dealing with interfaces that my issue spurious update statements, as it merely indicates whether a column was part of an update statement, and does not indicate whether the value actually changed.

For instance, this code:
update A set Value = 5 where Value = 5
...would result in the UPDATE() function indicating that a set of records were updated, whereas in reality they have the same value as before.

If you really want to check whether the value has changed, try something like this:
begin
update myTable
set UpdateTimeStamp=GetDate()
from myTable
inner join inserted i on i.ID=myTable.ID
inner join deleted d on d.ID=myTable.ID
where inserted.Value <> deleted.Value
or inserted.Value is null and deleted.Value is not null
or inserted.Value is not null and deleted.Value is null
...or use the BINARY_CHECKSUM() function to quickly compare multiple columns.