Why OBJECT_ID used while checking if a table exists or not

后端 未结 4 1466
渐次进展
渐次进展 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条回答
  •  -上瘾入骨i
    2021-01-30 07:25

    object_id = OBJECT_ID(N'[dbo].[YourTable]')
    

    object_id is the column name in sys.objects

    OBJECT_ID is a function that returns the ID for the object you specify, i.e. YourTable.

    You are comparing the object_id of YourTable with the object_id column in the sys.objects table. You need to replace YourTable with the table name you want to check already exists.

提交回复
热议问题