Running SQL Scripts

Using a text editor, you can create SQL scripts and run them with mfsql by using the /r command followed by the filename. A sample script file appears below. Note that mfsql recognizes the hash sign (#) as the comment identifier.

#############################################################
#  x.sql
#############################################################
create table foo(col1 char(10), col2 char (10) );

#now create an index for the file
create unique index ifoo_0 on foo(col1);

#insert values
insert into foo values ('1','1');

#insert a null value for col2
insert into foo values ('2', '');

# set the null character
/n !null!

#select some records
select * from foo;

#now exit
/q

Run this script by issuing the following command:

 -r x.sql

This will log into the default database with the default user and password information. It will then execute the script called x.sql.

If you wish, you can redirect the output to a file. For example

 –r x.sql > output.txt

The file output.txt would then contain:

COL1       COL2
 ---------- ----------
 1          1
 2          !null!