How do you use SQL to see whether a table exists or not?

Possible Duplicate:
SQL Server: Check if table exists
Oracle: If Table Exists

I'm trying to create a table and insert some values, but before I do I must make sure that the table doesn't already exist. How do you check for this?


您可以尝试简单地从中进行选择并捕获错误,否则您将需要编写特定于数据库的SQL以查询其各自的元数据表并在其中查找。


假设SQL Server ...查询sysobjects:

select * from sysobjects where xtype='U' and name ='tablename'

In MySQL, you can use the CREATE TABLE IF NOT EXISTS construct and run it before your INSERT query. This will create the table if it doesn't exist and will do nothing if the table is there.

CREATE TABLE IF NOT EXISTS myTable (
    ....
)

http://dev.mysql.com/doc/refman/5.1/en/create-table.html

http://docs.oracle.com/cd/E17952_01/refman-5.1-en/create-table.html

链接地址: http://www.djcxy.com/p/94440.html

上一篇: 检查表是否存在sql服务器

下一篇: 你如何使用SQL来查看表是否存在?