![]() | JDB SQL Reference | ![]() |
This chapter describes the utilities available with JDB:
Access a command line interactive SQL utility
isqldatabaseName
databaseName- Specifies the name of the database or
@systemif a database isn't available.
The
isqlutility is a command-line interactive editor for JDB that lets you to execute any database statement. It is provided as a command-driven alternative to the JISQL graphical environment described in Chapter 5, "Using JISQL."While
isqland JISQL are similar in many respects, they are not identical. JISQL has a series of macro commands that are not available inisql, so JISQL scripts containing these commands will not run underisql. Although the SQL commands inisqlend with a;as a termination character, all JISQL commands terminate with a;. Use the interactive SQL capability described here only if you want to bypass the JISQL environment.Starting ISQL
To start
isql, at the command line, type:$SMBASE/jdb/bin/isqldatabaseNamewhere
databaseNameis the name of an existing database or@systemif a database isn't available. The screen displays the following numeric prompt where you can enter any JDB statement:1>Creating a New Database
If this is your first JDB session, or if you want to create a new database, first start
isql. Generally, on UNIX systems, it is located in$SMBASE/jdb/bin.isqlAt the prompt, logon toJDB using@system:logon @systemOnce you are connected, create a new database by typing:
create databasedatabaseName;
databaseNamemust conform to the file naming conventions of the operating system.To connect to the new database in order to create database tables and enter data, enter:
logondatabaseNameExecuting SQL Statements
You can execute any SQL statement available in JDB by ending each database statement with a
;as the command terminator. For example:1> SELECT title_name, name, genre_code FROM titles;A line without a trailing semi-colon is concatenated with the next line until a semicolon is reached. Therefore, one statement can span multiple lines.
Executing ISQL Statements
Table A-1 lists the commands available in
isql. These commands allow you to edit a query, read in a query file, or execute an operating system command.Note: These commands do not end with a semi-colon. Also, in order for these commands to be recognized, each must start on the first character of a command line.
Exiting ISQL
To exit
isql, type:exitAn automatic commit is generated when you exit the
isqlsession using either thequitorexitcommands. Specifyrollbackif you do not want to keep your database changes.
Restore a transaction log
jdbrolldatabaseNamejournalName[journalName...]
databaseName- Specifies the name of the database.
journalName- Specifies the name of the journal file(s).
The
jdbrollutility allows you to update the database based on your log files.When you logon to a database for the first time, JDB creates a journal file named
j1databaseName. For example, a database having thevideobizwould have a journal file namedj1videobiz. The next time you log on, the information in the current file (j1videobiz) is copied to the filej0databaseName. If the file already exists, it is overwritten.
Translate an existing JDB database into its CREATE TABLE and INSERT statements
mksqldatabaseName
databaseName- Specifies the name of the database.
The
mksqlutility uses an existing JDB database to output a set of SQL statements from which the database could be rebuilt. For each table, it writes aCREATE TABLEstatement, followed by a series ofINSERTstatements for the data in the table.
The following result set illustrates a portion of the output for the actors table in the videobiz database.
![]()
Read rows in a database table to/from text files
tbldata [-ddelimiter] -xexportFiledatabaseNametableNametbldata [-ddelimiter] -iimportFiledatabaseNametableName
- -d
delimiter- Specifies the column delimiter. The delimiter character might need to be enclosed in quotation marks. For example, to specify a space as the delimiter:
tbldata -d " " -x exportFile databaseName tableNameIf no delimiter is specified,
tbldatausesTABas the delimiter.- -x
- Logs onto the specified database and writes each row of the specified table to the specified text file.
- -i
- Logs onto the specified database and inserts each row of the specified text file into the specified table.
exportFile- Name of the text file where the data will be written.
importFile- Name of the text file containing the data to be inserted into JDB.
databaseName- Name of the JDB database.
tableName- Name of the database table.
The
tbldatautility can be used two different ways:
- With the
-xargument to convert rows in a database table to a text file.
- With the
-iargument to insert rows into a database table from a text file.
With these options, you must specify both the database and the database table.
When using
-ioption, the database table must already exist. Also, the column values must be listed in the same order as the columns in the database table.
![]()
![]()
![]()
![]()