November 25, 2008 at 12:45 pm
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?
November 26, 2008 at 7:58 am
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
[font="Verdana"]Markus Bohse[/font]
November 26, 2008 at 8:24 am
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).
June 19, 2014 at 6:32 am
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! 😀
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply