Die Datenmanipulationssprache SQL



Ähnliche Dokumente
SQL. Datenmanipulation. Datenmanipulationssprache. Ein neues Tupel hinzufügen. Das INSERT Statement

Prakt. Datenbankprogrammierung. Sommersemester I,9: Datenmanipulation. Daten-Manipulations-Sprache. Das INSERT-Statement

Prakt. Datenbankprogrammierung. Sommersemester Was sind Constraints? I,11: Verwendung von Constraints. Festlegung von Constraints

Erzeugen von Constraints

Die relationale Abfragesprache SQL Structured Query Language

Prakt. Datenbankprogrammierung. Sommersemester 2005

Username and password privileges. Rechteverwaltung. Controlling User Access. Arten von Rechten Vergabe und Entzug von Rechten DBS1 2004

Art der Info: Technische Background Info Teil 2 (April 2002)

Erzeugung und Veränderung von Tabellen

Art der Info: Technische Background Info Teil 3 (April 2002)

SQL-Loader. Prof. Dr. Waldemar Rohde Dipl.-Ing. Jörg Höppner

Die bisher bereits bekannten Aggregatsfunktionen MIN, MAX, SUM, AVG, COUNT, VARIANCE und STDDEV wurden um FIRST und LAST erweitert.

Mengen- oder SET-Operatoren fassen das Ergebnis von zwei oder mehreren Teilabfragen zu einem Ergebnis zusammen.

Entspricht dem kartesischen Produkt von zwei oder mehr selektierten Tabellen ohne Join-Bedingung.

Die Datendefinitionssprache SQL

Views erzeugen. Datenbank - Objekte. Wozu braucht man Views? Was ist eine View?

Datenbanken Labor, MI : Übung 1 SQL - Abfragen Patrick Lipinski

Prakt. Datenbankprogrammierung. Sommersemester 2005

SQL Intensivpraktikum SS 2008

Variable. Interaktive Skripte

Prakt. Datenbankprogrammierung. Sommersemester Überblick über Trigger. II,11: Erstellen von Datenbank- Triggern. Datenbank-Trigger: Beispiel

Skripte schreiben. Überblick SQL*Plus. Einloggen in SQL*Plus. Tabellenstrukturen anzeigen

Oracle 8i und 9i New Features. DOAG November Peter Jensch, Trivadis GmbH

Loader. Oracle SQL*Loader. Einsatzmöglichkeit für den Import von Massendaten. 2. Datenbankworkshop der Ag Bioinformatik BIC-GH / PDW IPK

Trigger schreiben. Überblick über Trigger. Datenbank Trigger: Beispiel. Aufbau eines Triggers

Funktion definieren Gibt Summe der Gehälter zurück. Aufruf in einem SQL-Statement

Funktionen. Überblick über Stored Functions. Syntax zum Schreiben einer Funktion. Schreiben einer Funktion

Exercise (Part I) Anastasia Mochalova, Lehrstuhl für ABWL und Wirtschaftsinformatik, Kath. Universität Eichstätt-Ingolstadt 1

Installation MySQL Replikationsserver

SQL-Einführung Teil 2

Übung PL/SQL Trigger Lösungen

functions Two Types of SQL Functions

VGM. VGM information. HAMBURG SÜD VGM WEB PORTAL - USER GUIDE June 2016

Querying Data with Transact-SQL MOC 20761

Order Ansicht Inhalt

Abfragen (Queries, Subqueries)

Prakt. Datenbankprogrammierung. Sommersemester 2005

Oracle 10g Flashback. Andrea Held

Exercise (Part II) Anastasia Mochalova, Lehrstuhl für ABWL und Wirtschaftsinformatik, Kath. Universität Eichstätt-Ingolstadt 1

Prakt. Datenbankprogrammierung. Sommersemester I,5: Aggregieren von Daten mit Gruppen-Funktionen

Art der Info: Technische Background Info Teil 1 (April 2002)

1. General information Login Home Current applications... 3

i Korrekturlauf mit Acrobat Reader - Correction workflow using Acrobat Reader i.1 Vorbereitung / Preparations

Magic Figures. We note that in the example magic square the numbers 1 9 are used. All three rows (columns) have equal sum, called the magic number.

Arbeit mit zusammengesetzten Datentypen

Übungsblatt 8- Lösungsvorschlag

Übungsaufgaben mit Lösungen

Exercise (Part XI) Anastasia Mochalova, Lehrstuhl für ABWL und Wirtschaftsinformatik, Kath. Universität Eichstätt-Ingolstadt 1

Zusammengesetzte Datentypen

Üben von DDL und DML. Ergebnis:

p^db=`oj===pìééçêíáåñçêã~íáçå=

Exercise (Part VIII) Anastasia Mochalova, Lehrstuhl für ABWL und Wirtschaftsinformatik, Kath. Universität Eichstätt-Ingolstadt 1

Multi-temporale Datenbank Features in Oracle 12c Philipp Salvisberg

VGM. VGM information. HAMBURG SÜD VGM WEB PORTAL USER GUIDE June 2016

Oracle 12c: Neuerungen in PL/SQL. Roman Pyro DOAG 2014 Konferenz

Der SAS DataStep und die Prozedur SQL Cellent Finance Solutions GmbH Seite: 1

Transaktionen in Praxis. Dr. Karsten Tolle Vorl

Shaping the Future of Intelligence. PLATH Group 1

NoSQL mit Postgres 15. Juni 2015

Fakultät für Informatik & Wirtschaftsinformatik DB & IS II - SS Metadaten

Leseprobe: SQL mit MySQL - Band 4 Kompendium mit Online-Übungs-DB. Kompendium zur schnellen Kurzinformation der Datenbanksprache SQL/MySQL 5.

Cassandra Query Language (CQL)

SÄTZE MIT VARIABLER LÄNGE

Datenbanken SQL Einführung Datenbank in MySQL einrichten mit PhpMyAdmin

FEBE Die Frontend-Backend-Lösung für Excel

SQL and PL/SQL unleashed. Neuheiten bei Oracle 11g und Oracle 12c im Bereich SQL und PL/SQL

Grundlagen der Informatik III ERM-Modell Thema: Grundlagen der Datenbanken

Version/Datum: Dezember-2006

SQL structured query language

Referenzielle Integrität SQL

ReadMe zur Installation der BRICKware for Windows, Version ReadMe on Installing BRICKware for Windows, Version 6.1.2

VO Datenmodellierung. Katrin Seyr

Warum wird mein Index nicht benutzt?

6. Datenintegrität. Integritätsbedingungen

Hochschule Karlsruhe Technik und Wirtschaft Anhänge: Fakultät für Informatik und Wirtschaftsinformatik SS 2013 Prof. Schmidt.

SQL Intensivpraktikum SS 2008

Therefore the respective option of the password-protected menu ("UPDATE TUBE DATA BASE") has to be selected:

Oracle Analytic Functions

file:///c:/users/wpzsco/appdata/local/temp/tmp373d.tmp.htm

MySQL Cluster und MySQL Proxy

Umstellung eines Outlook Kontos von ActiveSync zu IMAP. Changing an Outlook account from ActiveSync to IMAP

MySQL Queries on "Nmap Results"

Whitepaper. Produkt: combit Relationship Manager. Datensatzhistorie mit dem SQL Server 2000 und combit GmbH Untere Laube Konstanz

Hadoop Demo HDFS, Pig & Hive in Action. Oracle DWH Konferenz 2014 Carsten Herbe


Prakt. Datenbankprogrammierung. Sommersemester 2005

Fortgeschrittene SQL-Techniken für APEX-Formulare und Reports

SQL. Fortgeschrittene Konzepte Auszug

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

Einführung in SQL. 1. Grundlagen SQL. Structured Query Language. Viele Dialekte. Unterteilung: i. DDL (Data Definition Language)

Oracle 10g Flashback. Andrea Held Business Management Systeme Deutsche Post ITSolutions. Deutsche Post ITSolutions GmbH

Referentielle Integrität

Isolationsstufen für Transaktionen. Dr. Karsten Tolle

Object Relational Mapping Layer

Oracle Indexing Primer

Referentielle Integrität

Fakultät für Informatik & Wirtschaftsinformatik DB & IS II - WS Metadaten. Andreas Schmidt Metadaten 1/17

Transaktionen in Praxis. Dr. Karsten Tolle Vorl

Anwendungsentwicklung Datenbanken SQL. Stefan Goebel

Fakultät für Informatik & Wirtschaftsinformatik DB & IS II - SS Trigger. Andreas Schmidt Trigger 1/25

Transkript:

Die Datenmanipulationssprache SQL Daten eingeben Daten ändern Datenbank-Inhalte aus Dateien laden Seite 1 Data Manipulation Language A DML statement is executed when you Add new rows to a table Modify existing rows in a table Remove existing rows from a table Seite 2

Adding a New Row to a Table 50 DEVELOPMENTDETROIT New row DEPT DEPTNO DNAME LOC ------ ---------- -------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON insert a new row into DEPT table DEPT DEPTNO DNAME LOC ------ ---------- -------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 50 DEVELOPMENTDETROIT Seite 3 The INSERT Statement Add new rows to a table by using the INSERT statement Only one row is inserted at a time with this syntax INSERT INTO table [(column [, column...])] VALUES (value [, value...]); Seite 4

Inserting New Rows Insert a new row containing values for each column Optionally list the columns in the INSERT clause List values in the default order of the columns in the table Enclose character and date values within single quotation marks SQL> INSERT INTO dept (deptno, dname, loc) 2 VALUES (50, 'DEVELOPMENT', 'DETROIT'); 1 row created. Seite 5 Inserting Rows with Null Values Implicit method: Omit the column from the column list SQL> INSERT INTO dept (deptno, dname ) 2 VALUES (60, 'MIS'); 1 row created. Explicit method: Specify the NULL keyword SQL> INSERT INTO dept 2 VALUES (70, 'FINANCE', NULL); 1 row created. Seite 6

Inserting SpecialValues The SYSDATE function records the current date and time SQL> INSERT INTO emp (empno, ename, job, 2 mgr, hiredate, sal, comm, 3 deptno) 4 VALUES (7196, 'GREEN', 'SALESMAN', 5 7782, SYSDATE, 2000, NULL, 6 10); 1 row created. Seite 7 Inserting Specific Date Values Add a new employee SQL> INSERT INTO emp 2 VALUES (2296,'AROMANO','SALESMAN',7782, 3 TO_DATE('FEB 3,97', 'MON DD, YY'), 4 1300, NULL, 10); 1 row created. Verify your addition EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ----- ------- -------- ---- --------- ---- ----- ----- 2296 AROMANO SALESMAN 7782 03-FEB-97 1300 10 Seite 8

Copying Rows from Another Table Write your INSERT statement with a subquery Do not use the VALUES clause Match the number of columns in the INSERT clause to those in the subquery SQL> INSERT INTO managers(id, name, salary, hiredate) 2 SELECT empno, ename, sal, hiredate 3 FROM emp 4 WHERE job = 'MANAGER'; 3 rows created. Seite 9 Changing Data in a Table EMP EMPNO ENAME JOB EMP... DEPTNO 7839 KING PRESIDENT 10 7698 BLAKE MANAGER 30 7782 CLARK MANAGER 10 7566 JONES MANAGER 20... EMPNO ENAME JOB update a row in EMP table... DEPTNO 7839 KING PRESIDENT 10 7698 BLAKE MANAGER 30 7782 CLARK MANAGER 10 20 7566 JONES MANAGER 20... Seite 10

The UPDATE Statement Modify existing rows with the UPDATE statement Update more than one row at a time, if required UPDATE SET [WHERE table column = value [, column = value] condition]; Seite 11 Updating Rows in a Table Specific row or rows are modified when you specify the WHERE clause SQL> UPDATE emp 2 SET deptno = 20 3 WHERE empno = 7782; 1 row updated. All rows in the table are modified if you omit the WHERE clause SQL> UPDATE employee 2 SET deptno = 20; 14 rows updated. Seite 12

Updating with Multiple-Column Subquery Update employee 7698 s job and department to match that of employee 7499 SQL> UPDATE emp 2 SET (job, deptno) = 3 (SELECT job, deptno 4 FROM emp 5 WHERE empno = 7499) 6 WHERE empno = 7698; 1 row updated. Seite 13 Updating Rows Based on Another Table Use subqueries in UPDATE statements to update rows in a table based on values from another table SQL> UPDATE employee 2 SET deptno = (SELECT deptno 3 FROM emp 4 WHERE empno = 7788) 5 WHERE job = (SELECT job 6 FROM emp 7 WHERE empno = 7788); 2 rows updated. Seite 14

Updating Rows: Integrity Constraint Error Department number 55 does not exist SQL> UPDATE emp 2 SET deptno = 55 3 WHERE deptno = 10; UPDATE emp * ERROR at line 1: ORA-02291: integrity constraint (USR.EMP_DEPTNO_FK) violated - parent key not found Seite 15 Removing a Row from a Table DEPT DEPTNO DNAME LOC ------ ---------- -------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 50 DEVELOPMENTDETROIT 60 MIS... delete a row from DEPT table DEPT DEPTNO DNAME LOC ------ ---------- -------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 60 MIS... Seite 16

The DELETE Statement You can remove existing rows from a table by using the DELETE statement DELETE [FROM] table [WHERE condition]; Seite 17 Deleting Rows from a Table Specific row or rows are deleted when you specify the WHERE clause SQL> DELETE FROM department 2 WHERE dname = 'DEVELOPMENT'; 1 row deleted. All rows in the table are deleted if you omit the WHERE clause SQL> DELETE FROM 4 rows deleted. department; Seite 18

Deleting Rows Based on Another Table Use subqueries in DELETE statements to remove rows from a table based on values from another table SQL> DELETE FROM employee 2 WHERE deptno = 3 (SELECT deptno 4 FROM dept 5 WHERE dname ='SALES'); 6 rows deleted. Seite 19 Deleting Rows: Integrity Constraint Error You cannot delete a row that contains a primary key that is used as a foreign key in another table SQL> DELETE FROM dept 2 WHERE deptno = 10; DELETE FROM dept * ERROR at line 1: ORA-02292: integrity constraint (USR.EMP_DEPTNO_FK) violated - child record found Seite 20

Datenbank-Inhalte aus anderen Oracle-Datenbanken laden Importprogramm IMP übernimmt von Oracle exportierte Daten einschl. Tabellenbeschreibung, Constraints, Rechten usw. Voraussetzung: mit EXP exportierte Dateien (Verträglichkeit der Versionen beachten!) Seite 21 Datenbank-Inhalte aus sequentiellen Dateien laden Ladeprogramm SQLLDR übernimmt Datensätze mit durch Trennzeichen getrennten Datenwerten in Oracle-Datenbanken unter Steuerung eines Control- Files Voraussetzung: Datenbank-Tabellen müssen vorher definiert sein; nur Daten werden übernommen Steuerfile beschreibt Zuordnung von Datei-Daten zu Tabellenspalten Beispiel: LOAD DATA INFILE * INTO TABLE bibliothek.leser FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '"' (vorname,name,str,plz,ort,lnr) BEGINDATA Thomas;Achtzehn;Turmstr. 21d;06124;Halle;22180533 Thomas;Ackermann;Thomas-Müntzer-Str. 16;06406;Bernburg-Strenzfeld;12032021... Seite 22

Summary Statement INSERT UPDATE DELETE Description Adds a new row to the table Modifies existing rows in the table Removes existing rows from the table IMP / EXP SQL*Loader Import aus anderen Oracle-Datenbanken Laden aus sequentiellen Dateien Seite 23