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.


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

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

Close the database connection.


See Also

| |

Related Topics

External Websites