DB2 at PRISM |
DB2 is running in the PRISM lab for 3421 students. A database has been created for the COSC-3421 A section. The database is named c3421a. |
If you are remote (that is, logging in from anywhere but in the PRISM lab), login to red (that is, red.cs.yorku.ca). If you are at the PRISM lab, log in to your favorite machine. All jun01-jun40 are also available to run db2. |
You have two ways to go. Entering into a db2 shell and working there, or issuing all your db2 commands from your LINUX shell. The choice is yours! |
At your UNIX
command prompt, type:
You should always do the last two commands above when you are done with
your DB2 session. The connect reset command drops your connection
to the database (say, c3421a). You will still be in the db2
shell after this, and could do other things. Like you could then connect
to another database. (But you have no need for doing this in this course.)
Or you could try to create a new database! (But since you probably
do not have DBA priviledges, DB2 probably won't let you.)
The disadvatage? You have to say connect reset and then connect to other to connect to database other. Big deal. Anyway, you'll be living in the same database for the durationof the course. |
The DB2 system has
some on-line help available. The command is "?. Some examples:
|
Anything you can
do in the db2 shell, you can likewise execute directly from the
UNIX
shell. For example:
|
Let us say you wanted
to write a bunch of SQL and DB2 commands in a file, and then have DB2 execute
those commands. You can do that. Say that your file with the commands is
named sql_file. At the Unix command prompt, type:
|
Note that you have
to end your DB2 / SQL commands with semi-colons when executing commands
from a file, but don't need them to end your commands otherwise. What gives?
Well, actually, DB2 gives you the choice in both cases really. You make
the choice via the "-t" flag with the db2 command, whether
running db2 as a UNIX command or to enter the DB2 shell.
With the "-t" flag, semi-colons are expected. Without it (so the
default), they are not expected. (In fact, DB2 will complain if you use
them in the
semi-colon-off case!!)
Why would you want to bother with the semi-colon-on option? Well, in the semi-colon-off option, a line return (CR) ends that DB2 / SQL command. And when you have long SQL commands to write, this is not very practical. Just try fitting one of your create commands for your project on one line! Actually, if you are playing semi-colon-off and have a long DB2 / SQL command, ending the partial command with a "\" and going to the next line works. So I always go with the semi-colon-on option. I need it as soon as I do anything serious. And I am used to it. Every other RDBMS like ORACLE expects the semi-colons. So it is best just to get used to it. Curious what the other flags to db2 above meant?
|
We shall be adding
pointers and helpful information as things progress.
However, database
systems are very complicated pieces of software and they take quite a bit
of effort to learn how to use, and much more effort to learn how to use
well. Just like a programming language. It would be literally impossible
for us to lay out here every command you will need to know.
This is a matter of pragmatics. But also you are computer scientists! (Or are soon to be released upon the world as such!) In the real world, you have to look up everything yourself. So be self-reliant. Go to the documentation when you need to. For more detailed help, refer to the Online Reference Manual. |