Can I add a new table or a column to an existing table to a database using Database Toolbox?

1 view (last 30 days)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
While using the Database Toolbox, you can give any valid SQL query to the EXEC command. You can use the 'CREATE TABLE' SQL command to create a new table in an existing database and use the 'ALTER' command to alter a table via EXEC. For example:
1. To create a table, use the CREATE command:
query = 'CREATE TABLE Person (LastName varchar,FirstName varchar,Address varchar,Age int)'
exec(conn, query)
where conn is the connection object to the database
2. To add a column to an existing database, use the ALTER command as follows:
a = exec(conn, 'ALTER TABLE Consumer ADD City varchar(30)')
For more information on the various SQL commands, refer to your database documentation. Note that the message field in each of the above command will contain
No ResultSet was produced
When modifying an existing table make sure that the database is not open for editing; this will cause concurrency issues.
If the database that you are trying to modify is open in write mode, you will get an error as described in the Related Solution listed below:

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!