%% Create Table and Add Column Using MySQL Native Interface
% This example shows how to connect to a database and manage the database structure using the MySQL® native interface. You can manage the database structure using the execute function.
%% Create Database Connection
% Create a MySQL native interface database connection to a MySQL database using the data source name, user name, and password.

datasource = "MySQLDataSource";
username = "root";
password = "matlab";
conn = mysql(datasource,username,password);

%% 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)

% Copyright 2020 The MathWorks, Inc.