DROP IF EXISTS VS DROP?

前端 未结 5 489
南方客
南方客 2020-12-07 09:29

Can someone tell me if there is any difference between

DROP IF EXISTS [TABLE_NAME]
DROP [TABLE_NAME]

I am askin

5条回答
  •  北海茫月
    2020-12-07 09:58

    If no table with such name exists, DROP fails with error while DROP IF EXISTS just does nothing.

    This is useful if you create/modifi your database with a script; this way you do not have to ensure manually that previous versions of the table are deleted. You just do a DROP IF EXISTS and forget about it.

    Of course, your current DB engine may not support this option, it is hard to tell more about the error with the information you provide.

提交回复
热议问题