tools for database projects
DESCRIPTION
TRANSCRIPT
![Page 1: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/1.jpg)
Tools for Database Projects
Syeda NessaTA for CS 6360
email: [email protected] Hour: Monday(11:00AM-1:00PM)
Tuesday(9:30 AM-11:30AM)Office Location:ECSS 4.705
This slide: http://www.utdallas.edu/~skn051000/cs6360/
![Page 2: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/2.jpg)
Agenda
We are going to discuss the tools necessary for doing your database projects. We are going to discuss:
Setting up your Oracle Account
Using Altova XMLSpy
PL/SQL issues
![Page 3: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/3.jpg)
Steps to set up your oracle account
Login to csoracle.utdallas.edu with your net id and password using putty.
Edit your .bash_profile file at your home folder using vi,emacs, nano,.. by adding the following lines at end of the file.
#####################
if [ -f /oracle/env.sh ]
then
. /oracle/env.sh
fi
#####################
![Page 4: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/4.jpg)
Steps to set up your oracle account
source the .bash_profile by typing:
csoracle> source .bash_profile You should get the message that “oracle
variable has been set”.
![Page 5: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/5.jpg)
Setting password for Oracle
change your oracle password by typing: csoracle> /oracle/oam.pl
Should get the following message
Modifying password for #######
Enter New Password:
Confirm New Password:
Password changed Successfully Login to oracle by typing:
csoracle > sqlplus
![Page 6: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/6.jpg)
In case of Error
if the previous steps did not work, please email me at [email protected] with the problem. Include what error messages you got during the process.
![Page 7: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/7.jpg)
Using Sqlplus
Once you have logged on to Oracle using sqlplus you will get SQL prompt to run any sql query.
Example:
SQL> spool out_test.txt
SQL> create table test_spool(a int, b char);
Table created.
SQL> spool off
![Page 8: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/8.jpg)
Spooling
Here “spool” command is used for recording all your activities in sql prompt.
In the above example I used “spool out_test.txt” command to start spooling and store all sql commands and outputs into out_test.txt file. This file will be stored in my home directory.
You have to give “spool off” command to stop spooling.
![Page 9: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/9.jpg)
Helpful Links
For reference on any sql function or command see the following page http://www.psoug.org/library.html http://oracleheva1.oracle.com/docs/cd/A87860_01/
doc/server.817/a85397.pdf For Oracle 10g
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/toc.htm
For general help http://infolab.stanford.edu/~ullman/fcdb/oracle/or-int
ro.html#0.1_creating+a+table
![Page 10: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/10.jpg)
Executing SQL From a File
Instead of executing SQL commands typed at a terminal, you can type the SQL command(s) into a file foo.sql and execute it by typing
SQL> @foo
sqlplus assumes by default the file extension ".sql" if there is no extension. So you could have entered @foo.sql at the SQL prompt, but if you wanted to execute the file bar.txt, you would have to enter @bar.txt.
References:http://infolab.stanford.edu/~ullman/fcdb/oracle/or-intro.html
![Page 11: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/11.jpg)
Leaving SQLPlus
To run any Shell command from SQL prompt you need to type
SQL > host <command>
For example to run pico to edit file assignment1.sql SQL> host pico assignment1.sql
After you exit from pico you will return to the SQL prompt.
To leave sqlplus, typeSQL> quit;
![Page 12: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/12.jpg)
Using Altova XMLSpy
To do the XML related Homework you need to use Altova XMLSpy installed in graduate Lab.
Using Altova XMLSpy you can generate xsd, xml, xquery etc.
There is also a 30 day evaluation version available in their web site that you can download, install and use in your personal computer [not in lab].
![Page 13: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/13.jpg)
Useful Links For XML
XML will be covered extensively in your class.
In addition, W3C has lot of free tutorials:
http://www.w3schools.com/xml/default.asp
http://www.w3schools.com/schema/default.asp
http://www.w3schools.com/xquery/default.asp
Altova has a series of flash demos on using their product:
http://www.altova.com/videos.asp?type=0&video=xmlspy
![Page 14: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/14.jpg)
Alternative to Altova
You can use any text editor to write your xml or xsd file.
There are some online tools you can use to validate your xml against your xsd.
http://tools.decisionsoft.com/schemaValidate/
http://www.w3.org/2001/03/webdata/xsv
To execute xquery you need to download saxon xml parser from
http://www.saxonica.com/download/saxonsa8-9j.zip
Unzip the file and run your xquery using
java -cp saxon8.jar net.sf.saxon.Query <xquery file>
![Page 15: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/15.jpg)
How To use Altova XMLSpy
First, build your XSD file.
Second, build your xml file against the xsd
Then you can run xquery on your xml file.
![Page 16: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/16.jpg)
Creating XSD file
XSD is the definition of data structure of your xml file.
First you need to define the structure
Then create the elements of the structure in a bottom up fashion
![Page 17: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/17.jpg)
Example: Cars
Suppose you are writing an XML to list cars.
The entry for each car will describe the model and the engine of the car.
The model section will describe the Make, Model, Trim and Year of the car.
The engine section will describe the size of the engine and the number of cylinders.
![Page 18: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/18.jpg)
Car XML Our XML will look like:<Cars>
<car>
<CarModel>
<Make>Ford</Make><Model>Mustang</Model><Year>1999</Year><Trim>GT</Trim>
</CarModel>
<Engine>
<Size>4.6L</Size>
<Cylinder>V6</Cylinder></Engine>
</car>
</Cars>
![Page 19: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/19.jpg)
Structure of Cars
The following structure can be inferred:
CarModelType is a ComplexType containing elements Make, Model, Year and Trim.
EngineType is a ComplexType containing elements Size and Cylinder.
CarsType is a ComplexType containing elements CarModel of type CarModelType and Engine of type EngineType.
Finally, the root element is Cars, containing element car of type CarsType.
![Page 20: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/20.jpg)
Constructing the XSD
Open Altova XMLSpy.
From File menu, choose New..., then choose xsd W3C XML Schema. Click OK.
From Schema Design menu, choose Display Diagram.
Right click on any empty space of the diagram and choose New Global > Complex Type.
In the diagram, type the name of the Complex type as CarModelType.
![Page 21: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/21.jpg)
Constructing the XSD (Contd.)
Right click on CarModelType, choose Add Child > Sequence.
Right click on the sequence, choose Add Child > Element.
Type the name of the element as Make.
Similarly add the other elements Model, Year and Trim to the sequence.
Similarly construct the global complex type EngineType with elements Size and Cylinder.
![Page 22: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/22.jpg)
Constructing the XSD (Contd.)
Construct the global complex type CarsType and add its elements CarModel and Engine.
Click on CarModel to select it.
In the Details pane on the right, set the Type property to CarModelType
Similarly set the type of Engine to EngineType
![Page 23: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/23.jpg)
Constructing the XSD (Contd.)
From Schema Design menu, choose Display All Globals.
Choose the root element. As we have not assigned the root element's name, it will show the name ENTER_NAME_OF_ROOT_ELEMENT_HERE.
From Schema Design menu, choose Display Diagram.
![Page 24: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/24.jpg)
Constructing the XSD (Contd.)
Set the name of the root element to Cars.
Add a sequence to Cars
Add an element car of type CarsType to the sequence.
From the Details pane of car, set maxOcc to unbounded.
This completes the construction of the Schema.
Save the schema as cars.xsd
![Page 25: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/25.jpg)
Generate XML File
Altova XMLSpy can generate a sample XML file for your schema. It is a good starting point for your XML file.
From DTD/Schema menu, choose Generate Sample XML File... Click OK.
You will see the sample XML file. Edit the contents, add some more car records, then save the file as cars.xml
![Page 26: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/26.jpg)
XQuery
Once you have your XML file, you can run query on the file.
An XML query is called an XQuery.
Details of XQuery will be covered extensively in your class.
We will see a simple XQuery here on the cars.xml
![Page 27: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/27.jpg)
Create XQuery
From File menu,
Choose New...
Choose xquery XML Query Language
Click OK.
Choose Generic XQuery Transformation
Click OK
Save the file as q1.xquery
![Page 28: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/28.jpg)
Write XQuery
Enter the following text into q1.xquery:<Cars>
{
for $d in distinct-values( doc("cars.xml")/Cars/car/CarModel/Model)
return <Model>{$d}</Model>
}
</Cars>
Save the file.
![Page 29: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/29.jpg)
Execute XQuery
From XSL/XQuery menu,
Choose Execute XQuery.
Choose the cars.xml file.
Click Execute.
You will see the output of the execution.
![Page 30: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/30.jpg)
PL/SQL
PL/SQL is Oracle's Procedural Language extension to SQL.
It will be extensively described into class and your 3rd project will be on PL/SQL, Trigger etc.
It is totally similar to running sql queries except for one point. You have to give the command in SQL prompt to enable outputs from PL SQL
SET SERVEROUTPUT ON
![Page 31: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/31.jpg)
Useful Links For PL/SQL,Trigger
http://infolab.stanford.edu/~ullman/fcdb/oracle/or-plsql.html
http://www.orafaq.com/faq/plsql
http://www.csee.umbc.edu/help/oracle8/server.815/a67842/toc.htm
Trigger/SQL
http://oraclesvca2.oracle.com/docs/cd/A87860_01/doc/server.817/a85397/toc.htm
![Page 32: Tools For Database Projects](https://reader033.vdocuments.mx/reader033/viewer/2022061221/54be76ee4a7959a4118b456f/html5/thumbnails/32.jpg)
The presentation is available at http://utdallas.edu/~skn051000/cs6360/
Thank You