%% Execute Non-SELECT SQL Statement
% Using a relational database connection, create and execute a non-SELECT SQL statement that deletes a database table.
% This example uses a Microsoft® SQL Server® Version 11.00.2100 database and the Microsoft SQL Server Driver 11.00.5058.
%
% Create a 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,'','');

%
% Load patient information into the MATLAB® workspace.

patients = readtable('patients.xls');

% Create the patients database table using the patient information.

tablename = 'patients';
sqlwrite(conn,tablename,patients)

%
% Import the data from the patients database table.

data = sqlread(conn,tablename);

%
% Delete the patients database table using the execute function.

sqlquery = ['DROP TABLE ' tablename];
execute(conn,sqlquery)

%
% Close the database connection.

close(conn)

% Copyright 2018 The MathWorks, Inc.