SQL QUERY OUTPUT

  • Whats the output for following code

    IF EXISTS (

    SELECT *

    FROM dbo.sysobjects

    WHERE 1=1

    AND id = object_id(N'dbo.xxx')

    AND OBJECTPROPERTY(id, N'IsUserTable') = 1)

    DROP TABLE dbo.xxx

  • What do you get when you run this code?

  • not at i executed this code.But which purpose these object propety and sysobjects are using in this code i am not getting

  • Okay, what do you think the code is trying do?

  • its a sql script for Droping the table from the database,if the condition success then the table would be dropped.But i am not getting the condition.

  • IF EXISTS (

    SELECT *

    FROM dbo.sysobjects

    WHERE 1=1

    AND id = object_id(N'dbo.xxx')

    AND OBJECTPROPERTY(id, N'IsUserTable') = 1)

    DROP TABLE dbo.xxx

    the condition 1=1 is redundent as it is always true.

    id = object_id(N'dbo.xxx') matches the object id

    OBJECTPROPERTY checks that it should be a user defined table

    u can get it all from google ot BOL

    Online Trainer For SQL DBA and Developer @RedBushTechnologies with 18 yrs exp.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply