Delete row if table exists SQL

后端 未结 9 982
旧时难觅i
旧时难觅i 2021-01-17 10:36

I have a script that drops a load of tables using DROP TABLE IF EXISTS, this works.

There is also a delete in this script to DELETE a row from another table that I d

9条回答
  •  南方客
    南方客 (楼主)
    2021-01-17 11:09

    To check in SQL SERVER,

    IF (EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'TheSchema' AND  TABLE_NAME = 'TheTable'))
    BEGIN
        --Do Stuff
    END
    

    To check in mysql:

    You simply count:

    SELECT COUNT(*)
    FROM information_schema.tables 
    WHERE table_schema = '[database name]' 
    AND table_name = '[table name]';
    

提交回复
热议问题