Your cart is currently empty!
This is an introductory lab to help you familiarize yourself with the tools that will be used throughout the course. Initialize PSQL Environment Following, we describe the steps associated with initializing our execution environment. Execute the following command to initialize the PSQL environment s o u r c e . /…
This is an introductory lab to help you familiarize yourself with the tools that will be used throughout the course.
Following, we describe the steps associated with initializing our execution environment.
Note: Examine the script you just executed. Look at every command and try to gure out its functionality. Pay special attention to the P GP ORT variable. After executing the above script type pg ctl status to view the status of the server, it should indicate that it is running correctly.
Note: Examine the script you just executed. Look at every command and try to gure out its functionality. What is the name of the database you just created?
s o u r c e . / stopPostgreDB . sh
Note: Examine the script you just executed. Look at every command and try to gure out its functionality.
1
After initializing your environment you should execute a series of SQL state-ments. DO NOT OPEN! a new terminal window, the scripts you just executed rely on system variables initialized through the previous scripts. Opening a new window will require initializing the values from scratch, hence running each script again after stopping the database correctly.
First, you will use the interactive environment PSQL environment to execute some SQL statements.
p s q l h l o c a l h o s t p $PGPORT $USER” DB”
We use $ to specify the value of the system variable with the corre-sponding name. In this case, $USER is your username. Alternatively, you can type the values directly if you know them. For example, if your username is vzois001 and the port number is set to 8192 then the command should look like:
p s q l h l o c a l h o s t p 8192 ” vzois001 DB ”
CREATE TABLE S t u d e n t s ( SID numeric ( 9 , 0 ) , Name ,! t e x t , Grade f l o a t ) ;
INSERT INTO S t u d e n t s VALUES ( 8 6 0 5 0 7 0 4 1 , ’ John ,! Anderson ’ , 3 . 6 7 ) ;
This statement will create a record in the table Students for a new student with name John Anderson, SID 860507041 and GPA 3.67.
INSERT INTO S t u d e n t s VALUES ( 8 6 0 3 0 9 0 6 7 , ’Tom Kamber ,! ’ , 3.12) ;
2
This statement will create a record in the table Students for a new student with name Tom Kamber, SID 860309041 and GPA 3.12.
SELECT SID , Name , Grade FROM S t u d e n t s WHERE SID = ,! 860507041;
This statement will retrieve all records from the table Students which satisfy the condition that the column SID has value 860507041.
DROP TABLE IF EXISTS S t u d e n t s ;
This statement is often used at the beginning of each script to avoid errors when re-initializing the tables.
p s q l h l o c a l h o s t ,! s q l
p $PGPORT $USER “DB” < s c r i p t .
Replace “script” with the name of your script.
3