我如何在C#中检查数据库(ACCESS或SQL)中是否存在表

问题描述:

我发现了很多与此问题有关的问题.

I found a lot of questions regarding with this question.

但是有没有简单的语句可以完成此任务?

But is there any simple statements to accomplish this task?

对于SQL和访问权限

IF (EXISTS (SELECT 1 FROM sys.tables WHERE name = 'table_name'))
BEGIN
    -- do stuff
END

sys.tables 可以还为您提供有关表对象的一些信息,例如is_replicated列告诉您该表是通过复制创建的,还是has_replication_filter列告诉您该表是否设置了复制过滤器

sys.tables can also give you some information about the table object, e.g. the is_replicated column tells you if the table was created by replication or the has_replication_filter column tells you if the table has a replication filter set up

NB:这是用于SQL Server

NB: this is for SQL Server

用于访问:

SELECT COUNT(*) as Exists from MsysObjects 
WHERE type = 1
AND name = 'MY_TABLE_NAME'