Executing NuoDB SQL Statements

The NuoDB SQL client, nuosql, is a command line tool for executing SQL statements against a database. You can experiment with nuosql by executing statements on the SQL QuickStart sample database that contains hockey data. By default, the database is named test on your local machine, with a user named dba whose password is goalie. This user has administrator privileges.

Note: If you did not already create the SQL QuickStart test database. go to Running the SQL QuickStart and then return here.

Open a terminal window. To start the nuosql command line tool, enter the following command. Substitute as necessary if you customized any parameters when you created the sample hockey database (test).

$ nuosql test@localhost --user dba --password goalie
SQL>

If you are successful then you see the SQL> prompt. On some platforms, specification of @localhost is optional.

After nuosql starts, you can execute standard SQL commands as you normally would with any SQL database. To see what tables are in the HOCKEY schema, try the following:

SQL> USE hockey;
SQL> SHOW tables;
     Tables in schema HOCKEY
        HOCKEY
        PLAYERS
        SCORING
        TEAMS
        VW_PLAYER_STATS is a view
SQL>

HOCKEY, PLAYERS, SCORING, and TEAMS are the sample tables and VW_PLAYER_STATS is the view created when you execute the SQL QuickStart.To display what is in the TEAMS table, run the following command:

SQL> SELECT * FROM teams ORDER BY name;  

YEAR  TMID  CONFID  DIVID  RANK   PLAYOFF G  W  L  T  OTL                  NAME
----- ----- ------- ------ ----- -------- -- -- -- -- ---- -------------------------------------
1916  TOB   0       0      4     0        14 7  7  0  0    228th Battalion
1972  ALB   0       WW     5     0        78 38 37 3  0    Alberta Oilers
2010  AND   WC      PC     2     CQF      82 47 30 0  5    Anaheim Ducks ...

Type help to display a list of NuoDB SQL commands:

SQL> HELP

ALTER SEQUENCE       Change definition of a sequence
ALTER TABLE          Change definition of a table
ALTER TRIGGER        Change definition of a trigger
ALTER USER           Change definition of a user 
...

Furthermore, you can type HELP followed by a command to get more information about that command:

SQL> HELP UPDATE
NAME
      UPDATE 
SYNOPSIS 
      UPDATE [schema.]table SET column = expression [, ...]  
          [WHERE condition ] 
DESCRIPTION 
      UPDATE changes the values of the columns specified for all rows that meet 
      the requirements specified by the WHERE condition clause. You are required 
      only to specify the columns to be modified. 
      Columns not specified by SET remain unchanged. 
      You must have write access to the table in order to modify it, as well as 
      read access to any table whose values are specified in the WHERE condition. 
SQL>

Exit nuosql by typing quit at the SQL> prompt:

SQL> quit

For more information: SQL Statements.

Next stop: Storefront demo.