How can I check if a table exists in a database (ACCESS or SQL) in C #

I have found many questions regarding this question.

But are there any simple statements to complete this task?

for SQL and ACCESS

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

sys.tables can also provide you some information about a table object, for example. the column is_replicatedtells you whether the table was created by replication or the column has_replication_filterindicates whether the table has a replication filter set

NB: this is for SQL Server

Edit: To access:

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

, SQL , , .

, ​​ , , , Oracle sys.all_tables.

+2

You can also use OBJECT_ID.

IF OBJECT_ID('table1') IS NOT NULL
print 'Exists' 
else
print 'Not Exists' 
0
source

Source: https://habr.com/ru/post/1778043/


All Articles