SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


sysstat & 0xf - what and why?


sysstat & 0xf - what and why?

Author
Message
Marcia Q
Marcia Q
Mr or Mrs. 500
Mr or Mrs. 500 (531 reputation)Mr or Mrs. 500 (531 reputation)Mr or Mrs. 500 (531 reputation)Mr or Mrs. 500 (531 reputation)Mr or Mrs. 500 (531 reputation)Mr or Mrs. 500 (531 reputation)Mr or Mrs. 500 (531 reputation)Mr or Mrs. 500 (531 reputation)

Group: General Forum Members
Points: 531 Visits: 699
I was supplied a script to run that contains the following:

if exists (select * from sysobjects where id = object_id('dbo.mytbl') and sysstat & 0xf = 3)
drop table dbo.mytbl
GO

In BOL, there's no real explanation of sysstat other than "Reserved for SQL Server internal use only. Future compatibility is not guaranteed."

When I googled it, I see quite a bit of sysstat & 0xf = 4 (not 3).
What is this? Is it really necessary to use it the way it is used above?
MarkusB
MarkusB
SSCertifiable
SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)

Group: General Forum Members
Points: 5999 Visits: 4208
The values in sysstat refer to what type of object it is. 3 means it's a user table. But I would advise against using this column in your scripts, because first of all in SQL 2005 you should work with sys. objects which doesn't have a sysstat column and second Microsoft can change the values in a future version.

The proper way of checking it is a user table would be using the OBJECTPROPERTY function.


IF EXISTS (SELECT * FROM sys.objects WHERE name ='mytbl'
AND OBJECTPROPERTY(OBJECT_ID('dbo.mytbl'),'IsUserTable')=1)
DROP TABLE dbo.mytbl



Markus Bohse
Marcia Q
Marcia Q
Mr or Mrs. 500
Mr or Mrs. 500 (531 reputation)Mr or Mrs. 500 (531 reputation)Mr or Mrs. 500 (531 reputation)Mr or Mrs. 500 (531 reputation)Mr or Mrs. 500 (531 reputation)Mr or Mrs. 500 (531 reputation)Mr or Mrs. 500 (531 reputation)Mr or Mrs. 500 (531 reputation)

Group: General Forum Members
Points: 531 Visits: 699
Thanks for the info. I'm used to working in 2000 and usually just check sysobjects where xtype = 'u' . I see where in 2005, the col is type instead of xtype. Will pass along to others the ObjectProperty(isusertable).
ge_jiang
ge_jiang
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 5
Actually "&" used here means Bitwise.
binary value of 0xf is 0000 1111
Example:
Bitwise A & B
A = 0000 1111
B = 0000 0011
-------------------
then: 0000 0011

"sysstat & 0xf =3" will guarantee that sysstat value is 3.

See MSDN site: http://msdn.microsoft.com/en-us/library/ms174965.aspx

Hope this can help! :-D
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search