This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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