Create Table and Add Column in SQLite Database
This example shows how to connect to an SQLite database and manage the database structure using the MATLAB® interface to SQLite. You can manage the database structure using the execute function.
Create SQLite Connection
Create the SQLite connection conn to the existing SQLite database file tutorial.db. The SQLite connection is an sqlite object.
dbfile = "tutorial.db";
conn = sqlite(dbfile);Create Database Table
Use the SQL CREATE statement to create the database table Person.
sqlquery = strcat("CREATE TABLE Person(lastname VARCHAR(250), ", ... "firstname VARCHAR(250), address VARCHAR(300), age INT)");
Create the table in the database using the database connection.
execute(conn,sqlquery)
Add Database Column
Use the SQL ALTER statement to add the database column city to the table Person.
sqlquery = "ALTER TABLE Person ADD city VARCHAR(30)";
execute(conn,sqlquery)Close Database Connection
close(conn)
See Also
Objects
Functions
Topics
- Import Data Using MATLAB Interface to SQLite
- Delete Data from SQLite Database
- Roll Back Data in SQLite Database