Εργαστήριο Ανάπτυξης Εφαρμογών Βάσεων Δεδομένων Εξάμηνο 7 ο
Oracle SQL Developer An Oracle Database stores and organizes information. Oracle SQL Developer is a tool for accessing and maintaining the data in the database. Τμ. Ψηφιακών Συστημάτων, Παν. Πειραιώς
Create a new user Create new connection( user name :DBLABADMIN) Αν κάνουμε expand το connection που δημιουργήσαμε (παραδείγματος χάριν SYSTEM), μπορούμε να δούμε ποιοι άλλοι χρήστες υπάρχουν στη βάση ή ποιους δημιουργήσαμε στη βάση μας Για κάθε έναν χρήστη υπάρχει κι ένα schema στη βάση Υπάρχουν από την εγκατάσταση της βάσης προϋπάρχοντες χρήστες, όπως οι hr, scott κτλ Για κάθε έναν από αυτούς τους χρήστες μπορούμε να κάνουμε δεξί κλικ και να επιλέξουμε Edit User και να ρυθμίσουμε ότι έχει σχέση με τον συγκεκριμένο χρήστη Να του αλλάξουμε password Να του δώσουμε δικαιώματα Να ελέγξουμε ότι ούτε το password έχει λήξει, ούτε ότι ο εκάστοτε λογαριασμός είναι κλειδωμένος (ελέγχουμε ότι δεν είναι επιλεγμένα τα: password expired, account is locked). Τμ. Ψηφιακών Συστημάτων, Παν. Πειραιώς
Create a new user (2) Create user Default tablespace:users Temporary Tablespace: TEMP Define Roles Τμ. Ψηφιακών Συστημάτων, Παν. Πειραιώς
New Connection Στο Tab Connections δημιουργούμε μια καινούρια σύνδεση, πατώντας δεξί κλικ και New Connection Connection Name : οποιοδήποτε όνομα θέλουμε για τη σύνδεση μας Username:.., password: hostname :dslab-dbs2 port = το 1521 και SID επιλέγουμε το όνομα για τη βάση που δηλώσαμε στην εγκατάσταση, παραδείγματος χάριν orcl. Πατάμε Test και αν είναι επιτυχής η σύνδεση Connect. Τμ. Ψηφιακών Συστημάτων, Παν. Πειραιώς
Δημιουργία Βάσης δεδομένων Κάνουμε εισαγωγή (import) εγγράφου βάσης δεδομένων στην Oracle, δηλαδή εκτελούμε τα SQL ερωτήματα που περιέχονται στο Createdatabase_lab.txt: για να δημιουργήσουμε τους πίνακες αντιγράφουμε στο κενό χώρο του connection που έχουμε δημιουργήσει τον κώδικα που αφορά στους πίνακες. Πατάμε Run Script και αν το ερώτημα δεν βγάλει σφάλμα, τότε πάμε στο tree view, πατάμε δεξί κλίκ πάνω στα Tables της σύνδεσης μας και Refresh και βλέπουμε τους πίνακες μας. Τμ. Ψηφιακών Συστημάτων, Παν. Πειραιώς
Δημιουργία Βάσης Δεδομένων Create Table View Table Attributes Data SQL queries Triggers etc Τμ. Ψηφιακών Συστημάτων, Παν. Πειραιώς
Creating Tables Using the Table Dialog create the DEPENDENTS table, which should contain the following columns: Id, FirstName, LastName, BirthDate, Relation, Gender, Benefits, and RelativeId. In the DEPENDENTS table no two rows have the same ID. The Gender column can only be set to M or F. the Benefits column stores large blocks of character data. Τμ. Ψηφιακών Συστημάτων, Παν. Πειραιώς
Creating Tables Using SQL create the AUDIT_RECORD_TBl table. This table will contain two columns. The user_value column is of the data type varchar2, and the date_recorded column is of the data type timestamp. Τμ. Ψηφιακών Συστημάτων, Παν. Πειραιώς
Execute statement Refresh tables Τμ. Ψηφιακών Συστημάτων, Παν. Πειραιώς
Create a copy of the table by using the Action Menus. Τμ. Ψηφιακών Συστημάτων, Παν. Πειραιώς
create a copy of the table by using the appropriate SQL statement. Τμ. Ψηφιακών Συστημάτων, Παν. Πειραιώς
Execute statement Refresh tables Τμ. Ψηφιακών Συστημάτων, Παν. Πειραιώς
Managing Constraints What Are Constraints? Data integrity ensures the consistency and correctness of data stored in a database. Such integrity can be enforced by incorporating business rules. Constraint sare the rules that are enforced on data stored in a table. Why Should I Use Constraints? You can use constraints to do the following: Enforce rules on the data in a table whenever a row is updated, inserted, or deleted from that table Prevent the deletion of a table if there are dependencies from other tables Τμ. Ψηφιακών Συστημάτων, Παν. Πειραιώς
Types of Constraints: PRIMARY KEY FOREIGN KEY CHECK UNIQUE NOT NULL Τμ. Ψηφιακών Συστημάτων, Παν. Πειραιώς
Creating Constraints Constraints can be enforced at two levels: Column level Table level A constraint can be created with either of the following statements: CREATE TABLE ALTER TABLE With the ALTER TABLE statement, you can disable or enable the imposed constraint without dropping it or re-creating it: Disable a constraint by using the DISABLE clause. Enable a constraint by using the ENABLE clause. Τμ. Ψηφιακών Συστημάτων, Παν. Πειραιώς
DISABLE CONSTRAINT Τμ. Ψηφιακών Συστημάτων, Παν. Πειραιώς
Reviewing Constraint Information Τμ. Ψηφιακών Συστημάτων, Παν. Πειραιώς
DROP TABLE Τμ. Ψηφιακών Συστημάτων, Παν. Πειραιώς
Accessing Data Τμ. Ψηφιακών Συστημάτων, Παν. Πειραιώς
need to evaluate the hire dates and start dates of all employees. We can find the hire date EMPLOYEES table and the start dates in the JOB_HISTORY table. These two columns ar erently. Τμ. Ψηφιακών Συστημάτων, Παν. Πειραιώς
you might want to find employees, their dependents' names, and the department names for those employees. This requires accessing three tables:- EMPLOYEES, DEPENDENTS, and DEPARTMENTS. Τμ. Ψηφιακών Συστημάτων, Παν. Πειραιώς