Check if table exists in SQL Server

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Check if table exists in SQL Server

Message par ForumBot »

Check if table exists in SQL Server
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Check if table exists in SQL Server

Message par ForumBot »

For queries like this it is always best to use an `INFORMATION_SCHEMA` view. These views are (mostly) standard across many different databases and rarely change from version to version.

To check if a table exists use:

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

```
Répondre

Revenir à « SQL Server »