Q:

Create Database and table

I have to create a database and afterwards create a table within the database created.
I have connected to the master on my connection string, but and I want to add the new database name I have just created within the Initial Catalog when connecting and creating the table.
This is what I have
string conn = "SERVER=BRIAN-PC\\SQLEXPRESS; Initial Catalog=master; user id =sa; Password=kagiso";

            String str = "CREATE DATABASE IF NOT EXIST PSAHoldings ON PRIMARY"
                + "(NAME = PSAHoldings_Data,"
                + "FILENAME = 'C:\\PSAHoldings.mdf'',"
                + "SIZE = 2MB, FILEGROWTH =10%)"
                + "LOG ON (NAME = PSAHoldings_Log,"
                + "FILENAME = 'C:\\PSAHoldingsLog,idf',"
                + "SIZE = 1MB,"
                + "FILEGROTH = 10%)";

SqlConnection connection = new SqlConnection(conn);
            connection.Open();

try
            {
                //SqlCommand to create database
                SqlCommand cmd = new SqlCommand(str, connection);
                cmd.ExecuteNonQuery();

                MessageBox.Show("DataBase was successfully created", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);

string connect = "Data Source=Esther-PC\\SQLEXPRESS; Initial Catalog=PSAHoldings; user id =sa; Password=kagiso";

            string table = "CREATE TABLE IF NOT EXIST t_original (" +
                "empId varChar(10) NOT NULL PRIMARY KEY," +
                "paycode varChar(10) NOT NULL," +
                "amount int NOT NULL," +
                ")";

            SqlConnection con = new SqlConnection(connect);
            con.Open();

            SqlCommand createTable = new SqlCommand(table, con);
            createTable.ExecuteNonQuery();
            }
}
            catch (SqlException sqlEx)
            {
                MessageBox.Show(sqlEx.ToString(), "Exception Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                connection.Close();
                con.Close();
            }

When I run the application I keep on getting exception errors.
The EXCEPTION ERROR reads it says System.Data.SqlClient.SqlException(0x80131904): Incorrect synax near the keyword 'IF'. expression of non-boolean type specified in a context where a condition is expected, near 'PSAHoldings', Unclosed quotation mark after the character string 'Size=1mb, filegrowth=10%)'.

A:

I don't think there's such code as CREATE DATABASE IF NOT EXIST - Can't find any mention of it on MSDN:
https://msdn.microsoft.com/en-us/library/ms176061.aspx
Try this.
IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = 'PSAHoldings')
  CREATE DATABASE PSAHoldings ON PRIMARY 
    (NAME = PSAHoldings_Data,
    FILENAME = 'C:\\PSAHoldings.mdf',
    SIZE = 3MB, FILEGROWTH =10%)
    LOG ON (NAME = PSAHoldings_Log,
    FILENAME = 'C:\\PSAHoldingsLog.idf',
    SIZE = 1MB,
    FILEGROWTH = 10%)

(Note some other mis-types fixed also changed file size to 3MB as I had an error saying it needed at least 3MB)

