Tools For Database Projects


Published on

Published in: Technology, Business
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Tools For Database Projects

  1. 1. Tools for Database Projects Syeda Nessa TA for CS 6360 email: [email_address] Office Hour: Monday(11:00AM-1:00PM)‏ Tuesday(9:30 AM-11:30AM)‏ Office Location:ECSS 4.705 This slide:
  2. 2. Agenda <ul><li>We are going to discuss the tools necessary for doing your database projects. We are going to discuss: </li></ul><ul><ul><li>Setting up your Oracle Account </li></ul></ul><ul><ul><li>Using Altova XMLSpy </li></ul></ul><ul><ul><li>PL/SQL issues </li></ul></ul>
  3. 3. Steps to set up your oracle account <ul><li>Login to with your net id and password using putty. </li></ul><ul><li>Edit your .bash_profile file at your home folder using vi,emacs, nano,.. by adding the following lines at end of the file. </li></ul><ul><ul><ul><li>##################### </li></ul></ul></ul><ul><ul><ul><li>if [ -f /oracle/ ] </li></ul></ul></ul><ul><ul><ul><li>then </li></ul></ul></ul><ul><ul><ul><li>. /oracle/ </li></ul></ul></ul><ul><ul><ul><li>fi </li></ul></ul></ul><ul><ul><ul><li>##################### </li></ul></ul></ul>
  4. 4. Steps to set up your oracle account <ul><li>source the .bash_profile by typing: </li></ul><ul><ul><li>csoracle> source .bash_profile </li></ul></ul><ul><li>You should get the message that “oracle variable has been set”. </li></ul>
  5. 5. Setting password for Oracle <ul><li>change your oracle password by typing: </li></ul><ul><ul><li>csoracle> /oracle/ </li></ul></ul><ul><li>Should get the following message </li></ul><ul><ul><li>Modifying password for ####### </li></ul></ul><ul><ul><li>Enter New Password: </li></ul></ul><ul><ul><li>Confirm New Password: </li></ul></ul><ul><ul><li>Password changed Successfully </li></ul></ul><ul><li>Login to oracle by typing: </li></ul><ul><ul><li>csoracle > sqlplus </li></ul></ul>
  6. 6. In case of Error <ul><li>if the previous steps did not work, please email me at skn051000 with the problem. Include what error messages you got during the process. </li></ul>
  7. 7. Using Sqlplus <ul><li>Once you have logged on to Oracle using sqlplus you will get SQL prompt to run any sql query. </li></ul><ul><li>Example: </li></ul><ul><ul><li>SQL> spool out_test.txt </li></ul></ul><ul><ul><li>SQL> create table test_spool(a int, b char); </li></ul></ul><ul><ul><li>Table created. </li></ul></ul><ul><ul><li>SQL> spool off </li></ul></ul>
  8. 8. Spooling <ul><li>Here “spool” command is used for recording all your activities in sql prompt. </li></ul><ul><li>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. </li></ul><ul><li>You have to give “spool off” command to stop spooling. </li></ul>
  9. 9. Helpful Links <ul><li>For reference on any sql function or command see the following page </li></ul><ul><ul><li> </li></ul></ul><ul><ul><li> </li></ul></ul><ul><li>For Oracle 10g </li></ul><ul><ul><li> </li></ul></ul><ul><li>For general help </li></ul><ul><ul><li> </li></ul></ul>
  10. 10. Executing SQL From a File <ul><li>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 </li></ul><ul><ul><li>SQL> @foo </li></ul></ul><ul><li>sqlplus assumes by default the file extension &quot;.sql&quot; 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. </li></ul><ul><li>References: </li></ul>
  11. 11. Leaving SQLPlus <ul><li>To run any Shell command from SQL prompt you need to type </li></ul><ul><ul><li>SQL > host <command> </li></ul></ul><ul><ul><li>For example to run pico to edit file assignment1.sql </li></ul></ul><ul><ul><ul><li>SQL> host pico assignment1.sql </li></ul></ul></ul><ul><ul><li>After you exit from pico you will return to the SQL prompt. </li></ul></ul><ul><li>To leave sqlplus, type </li></ul><ul><ul><li>SQL> quit; </li></ul></ul>
  12. 12. Using Altova XMLSpy <ul><li>To do the XML related Homework you need to use Altova XMLSpy installed in graduate Lab. </li></ul><ul><li>Using Altova XMLSpy you can generate xsd, xml, xquery etc. </li></ul><ul><li>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]. </li></ul>
  13. 13. Useful Links For XML <ul><li>XML will be covered extensively in your class. </li></ul><ul><li>In addition, W3C has lot of free tutorials: </li></ul><ul><ul><li> </li></ul></ul><ul><ul><li> </li></ul></ul><ul><ul><li> </li></ul></ul><ul><li>Altova has a series of flash demos on using their product: </li></ul><ul><ul><li> </li></ul></ul>
  14. 14. Alternative to Altova <ul><li>You can use any text editor to write your xml or xsd file. </li></ul><ul><li>There are some online tools you can use to validate your xml against your xsd. </li></ul><ul><ul><li> </li></ul></ul><ul><ul><li> </li></ul></ul><ul><li>To execute xquery you need to download saxon xml parser from </li></ul><ul><ul><li> </li></ul></ul><ul><ul><li>Unzip the file and run your xquery using </li></ul></ul><ul><ul><ul><li>java -cp saxon8.jar net.sf.saxon.Query <xquery file> </li></ul></ul></ul>
  15. 15. How To use Altova XMLSpy <ul><li>First, build your XSD file. </li></ul><ul><li>Second, build your xml file against the xsd </li></ul><ul><li>Then you can run xquery on your xml file. </li></ul>
  16. 16. Creating XSD file <ul><li>XSD is the definition of data structure of your xml file. </li></ul><ul><ul><li>First you need to define the structure </li></ul></ul><ul><ul><li>Then create the elements of the structure in a bottom up fashion </li></ul></ul>
  17. 17. Example: Cars <ul><li>Suppose you are writing an XML to list cars. </li></ul><ul><ul><li>The entry for each car will describe the model and the engine of the car. </li></ul></ul><ul><ul><ul><li>The model section will describe the Make, Model, Trim and Year of the car. </li></ul></ul></ul><ul><ul><ul><li>The engine section will describe the size of the engine and the number of cylinders. </li></ul></ul></ul>
  18. 18. Car XML <ul><li>Our XML will look like: </li></ul><ul><li><Cars> </li></ul><ul><ul><li><car> </li></ul></ul><ul><ul><ul><li><CarModel> </li></ul></ul></ul><ul><ul><ul><ul><li><Make>Ford</Make> </li></ul></ul></ul></ul><ul><ul><ul><ul><li><Model>Mustang</Model> </li></ul></ul></ul></ul><ul><ul><ul><ul><li><Year>1999</Year> </li></ul></ul></ul></ul><ul><ul><ul><ul><li><Trim>GT</Trim> </li></ul></ul></ul></ul><ul><ul><ul><li></CarModel> </li></ul></ul></ul><ul><ul><ul><li><Engine> </li></ul></ul></ul><ul><ul><ul><ul><li><Size>4.6L</Size> </li></ul></ul></ul></ul><ul><ul><ul><ul><li><Cylinder>V6</Cylinder> </li></ul></ul></ul></ul><ul><ul><ul><li></Engine> </li></ul></ul></ul><ul><ul><li></car> </li></ul></ul><ul><li></Cars> </li></ul>
  19. 19. Structure of Cars <ul><li>The following structure can be inferred: </li></ul><ul><ul><li>CarModelType is a ComplexType containing elements Make , Model , Year and Trim . </li></ul></ul><ul><ul><li>EngineType is a ComplexType containing elements Size and Cylinder . </li></ul></ul><ul><ul><li>CarsType is a ComplexType containing elements CarModel of type CarModelType and Engine of type EngineType. </li></ul></ul><ul><ul><li>Finally, the root element is Cars , containing element car of type CarsType. </li></ul></ul>
  20. 20. Constructing the XSD <ul><li>Open Altova XMLSpy. </li></ul><ul><li>From File menu, choose New..., then choose xsd W3C XML Schema. Click OK. </li></ul><ul><li>From Schema Design menu, choose Display Diagram. </li></ul><ul><li>Right click on any empty space of the diagram and choose New Global > Complex Type. </li></ul><ul><li>In the diagram, type the name of the Complex type as CarModelType. </li></ul>
  21. 21. Constructing the XSD (Contd.)‏ <ul><li>Right click on CarModelType, choose Add Child > Sequence. </li></ul><ul><li>Right click on the sequence, choose Add Child > Element. </li></ul><ul><li>Type the name of the element as Make. </li></ul><ul><li>Similarly add the other elements Model, Year and Trim to the sequence. </li></ul><ul><li>Similarly construct the global complex type EngineType with elements Size and Cylinder. </li></ul>
  22. 22. Constructing the XSD (Contd.)‏ <ul><li>Construct the global complex type CarsType and add its elements CarModel and Engine . </li></ul><ul><li>Click on CarModel to select it. </li></ul><ul><li>In the Details pane on the right, set the Type property to CarModelType </li></ul><ul><li>Similarly set the type of Engine to EngineType </li></ul>
  23. 23. Constructing the XSD (Contd.)‏ <ul><li>From Schema Design menu, choose Display All Globals . </li></ul><ul><li>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 . </li></ul><ul><li>From Schema Design menu, choose Display Diagram . </li></ul>
  24. 24. Constructing the XSD (Contd.)‏ <ul><li>Set the name of the root element to Cars . </li></ul><ul><li>Add a sequence to Cars </li></ul><ul><li>Add an element car of type CarsType to the sequence. </li></ul><ul><li>From the Details pane of car, set maxOcc to unbounded . </li></ul><ul><li>This completes the construction of the Schema. </li></ul><ul><li>Save the schema as cars.xsd </li></ul>
  25. 25. Generate XML File <ul><li>Altova XMLSpy can generate a sample XML file for your schema. It is a good starting point for your XML file. </li></ul><ul><li>From DTD/Schema menu, choose Generate Sample XML File... Click OK . </li></ul><ul><li>You will see the sample XML file. Edit the contents, add some more car records, then save the file as cars.xml </li></ul>
  26. 26. XQuery <ul><li>Once you have your XML file, you can run query on the file. </li></ul><ul><li>An XML query is called an XQuery . </li></ul><ul><li>Details of XQuery will be covered extensively in your class. </li></ul><ul><li>We will see a simple XQuery here on the cars.xml </li></ul>
  27. 27. Create XQuery <ul><li>From File menu, </li></ul><ul><ul><li>Choose New... </li></ul></ul><ul><ul><li>Choose xquery XML Query Language </li></ul></ul><ul><ul><li>Click OK . </li></ul></ul><ul><ul><li>Choose Generic XQuery Transformation </li></ul></ul><ul><ul><li>Click OK </li></ul></ul><ul><li>Save the file as q1.xquery </li></ul>
  28. 28. Write XQuery <ul><li>Enter the following text into q1.xquery : </li></ul><ul><li><Cars> </li></ul><ul><li>{ </li></ul><ul><li>for $d in distinct-values( doc(&quot;cars.xml&quot;)/Cars/car/CarModel/Model) </li></ul><ul><ul><li>return <Model>{$d}</Model> </li></ul></ul><ul><li>} </li></ul><ul><li></Cars> </li></ul><ul><li>Save the file. </li></ul>
  29. 29. Execute XQuery <ul><li>From XSL/XQuery menu, </li></ul><ul><ul><li>Choose Execute XQuery . </li></ul></ul><ul><ul><li>Choose the cars.xml file. </li></ul></ul><ul><ul><li>Click Execute . </li></ul></ul><ul><li>You will see the output of the execution. </li></ul>
  30. 30. PL/SQL <ul><li>PL/SQL is Oracle's Procedural Language extension to SQL. </li></ul><ul><li>It will be extensively described into class and your 3 rd project will be on PL/SQL, Trigger etc. </li></ul><ul><li>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 </li></ul><ul><ul><li>SET SERVEROUTPUT ON </li></ul></ul>
  31. 31. Useful Links For PL/SQL,Trigger <ul><li> </li></ul><ul><li> </li></ul><ul><li> </li></ul><ul><li>Trigger/SQL </li></ul><ul><ul><li> </li></ul></ul>
  32. 32. The presentation is available at Thank You