Sysstat in SQL Query


sysstat used in SQL server to map the type of the Objects like stored procedures, triggers etc. These are mainly used to check the availability or is created already. If it is created then we can modify or delete those things.

sysstat & 0xf examples


View:


View can be identified in a table using sysstat & 0xf = 2 in the sql query


if exists (select * from sysobjects where id = object_id('dbo.view_name') and sysstat & 0xf = 2)
drop view "dbo"."view_name"


Table


User defined Table can be identified in a database using sysstat & 0xf = 3 in the sql query


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


Stored Procedure


Stored Procedure in a database can be identified in a table using sysstat & 0xf = 4 in the sql query


if exists (select * from sysobjects where id = object_id('dbo.Procedure_name') and sysstat & 0xf = 4)
drop procedure dbo.Procedure_name


Default


Default can be identified in a table using sysstat & 0xf = 6 in the sql query


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


Trigger


Trigger can be identified in a table using sysstat & 0xf = 8 in the sql query


if exists (select * from sysobjects where id = object_id('dbo.Trigger_name') and sysstat & 0xf = 8)
drop trigger dbo.Trigger_name


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: