How to get table list in database, using MS SQL 2008?

后端 未结 3 569
感动是毒
感动是毒 2021-02-06 23:05

I want to verify if a table exists in a database, and if it doesn\'t exist, to create it. How can I get a list of all the tables in the current database?

I could get the

3条回答
  •  广开言路
    2021-02-06 23:12

    This should give you a list of all the tables in your database

    SELECT Distinct TABLE_NAME FROM information_schema.TABLES
    

    So you can use it similar to your database check.

    If NOT EXISTS(SELECT Distinct TABLE_NAME FROM information_schema.TABLES Where TABLE_NAME = 'Your_Table')
    BEGIN
        --CREATE TABLE Your_Table
    END
    GO
    

提交回复
热议问题