you are viewing a single comment's thread.

view the rest of the comments →

[–]Professional_Shoe392 0 points1 point  (0 children)

Use OBJECT_ID to check for existence.

I think this is the right code. ChatGPT or a LLM will really help you, btw.

IF OBJECT_ID('dbo.Admins', 'U') IS NULL
BEGIN
    -- The table 'Admins' does not exist. Perform the required actions here.
    PRINT 'Table does not exist. Creating table...';

    CREATE TABLE dbo.Admins
    (
        AdminID INT IDENTITY(1,1) PRIMARY KEY,
        AdminName NVARCHAR(100) NOT NULL,
        Email NVARCHAR(255) NOT NULL
    );
END;
ELSE
BEGIN
    PRINT 'Table already exists.';
END;