I want to create sql script which will work on server to check if database not exists then create new and if it exist then update its tables and SP's. but the problem is incase of its not exist , it create database but the tables and sp's gone to master database.

sample.

```
    DECLARE @dbname nvarchar(128)
    SET @dbname = N'ABC'

    IF (NOT EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE ('[' + 
    name + ']' = @dbname OR name = @dbname)))
    BEGIN
        PRINT 'New Database '
        CREATE DATABASE [ABC];
        USE ABC;  // This use statement is not working i supposed

        CREATE TABLE [dbo].[Product_Container](
            [ProductID] [int] NOT NULL,
            [ContainerID] [int] NOT NULL,
            [AssociatedProductID] [int] NOT NULL
        ) ON [PRIMARY]

         END
    ELSE
        BEGIN
           PRINT 'Existing Database '
        END

```