Main Content

Create Table and Add Column

This example shows how to connect to a database and manage the database structure. You can manage the database structure using the execute function.

Create an ODBC database connection to a Microsoft® SQL Server® database with Windows® authentication. Specify a blank user name and password.

datasource = 'MS SQL Server Auth';
conn = database(datasource,'','');

Use the SQL CREATE statement to create the table Person.

sqlquery = ['CREATE TABLE Person(LastName varchar, ' ...
    'FirstName varchar,Address varchar,Age int)'];

Create the table in the database using the database connection.

execute(conn,sqlquery)

Use the SQL ALTER statement to add the column City to the table Person.

sqlquery = 'ALTER TABLE Person ADD City varchar(30)'; 
execute(conn,sqlquery)

Close the database connection.

close(conn)

See Also

| |

Related Topics

External Websites