Why OBJECT_ID used while checking if a table exists or not

后端 未结 4 1465
渐次进展
渐次进展 2021-01-30 06:48

I need to check if a table in SQL exist or not.

If not it must create one automatically.

Now I researched and found this code:

IF  NOT EXISTS (SE         


        
4条回答
  •  既然无缘
    2021-01-30 07:33

    OBJECT_ID() is a function which returns the Object ID. See the documentation:

    Returns the database object identification number of a schema-scoped object.

    http://msdn.microsoft.com/en-us/library/ms190328.aspx


    By passing it certain parameters (ie. your table details), it will return an ID. You can then compare this with the IDs in the sys.objects table to check whether it currently exists.

提交回复
热议问题