Search code examples
c#sql-serveramazon-web-servicescreate-table

Amazon AWS RDS - How to Programmatically Create a MS SQL Table in C#


I've create an Amazon AWS RDS MS SQL instance. I want to programmatically create a database followed by a table. I've created a connection using a connection string that has no "Database=" parameter. First I create the database, next I want to create a table using the same connection. How can I specify that the table is to be created using the newly created database? I know I can close the connection and reopen with a "Database=" parameter but I would like to create the table without an additional close/open.

Here is the sql command that I'm using to create a table. Is there a way to specify the database name "Contacts" using a sql command?

CREATE TABLE ContactDetails (Id INT NOT NULL PRIMARY KEY)

Solution

  • Answering my own question ... the solution is to prepend USE to the CREATE TABLE command:

    USE Contacts; CREATE TABLE ContactDetails (Id INT NOT NULL PRIMARY KEY)
    

    I have not found an Amazon RDS API call to create or drop a table. Anyone?