Sql: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
(Die Seite wurde neu angelegt: „== Tipps und Tricks == Tabelle kopieren: <pre>create table person_backup as select * from person; </pre> Zurückkopieren: <pre>truncate person; insert into person…“) |
|||
Zeile 6: | Zeile 6: | ||
<pre>truncate person; | <pre>truncate person; | ||
insert into person select * from person_backup; | insert into person select * from person_backup; | ||
</pre> | |||
== Test-DB == | |||
<pre>create table region ( | |||
rid integer primary key, | |||
name varchar(64) | |||
); | |||
create table person ( | |||
pid integer primary key, | |||
name varchar(64), | |||
rid integer references region(rid) | |||
); | |||
create table sale ( | |||
sid integer primary key, | |||
pid integer references person(pid), | |||
price numeric(13,2), | |||
time date | |||
); | |||
insert into region values(1, 'Baden-Würtemberg'); | |||
insert into region values(2, 'Bayern'); | |||
insert into region values(3, 'Hessen'); | |||
insert into person values(1, 'Mayer', 2); | |||
insert into person values(2, 'Huber', 2); | |||
insert into person values(3, 'Schmidt', 3); | |||
insert into person values(4, 'Seggele', 1); | |||
insert into sale values(1, 1, 100, '2016-07-22'); | |||
insert into sale values(2, 1, 200, '2016-08-22); | |||
insert into sale values(3, 2, 300, '2016-09-03'); | |||
insert into sale values(4, 2, 400, '2016-10-09'); | |||
insert into sale values(5, 4, 500, '2016-11-22'); | |||
insert into sale values(6, 4, 600, '2016-12-02'); | |||
</pre> | </pre> | ||
Version vom 2. Februar 2017, 22:01 Uhr
Tipps und Tricks
Tabelle kopieren:
create table person_backup as select * from person;
Zurückkopieren:
truncate person; insert into person select * from person_backup;
Test-DB
create table region ( rid integer primary key, name varchar(64) ); create table person ( pid integer primary key, name varchar(64), rid integer references region(rid) ); create table sale ( sid integer primary key, pid integer references person(pid), price numeric(13,2), time date ); insert into region values(1, 'Baden-Würtemberg'); insert into region values(2, 'Bayern'); insert into region values(3, 'Hessen'); insert into person values(1, 'Mayer', 2); insert into person values(2, 'Huber', 2); insert into person values(3, 'Schmidt', 3); insert into person values(4, 'Seggele', 1); insert into sale values(1, 1, 100, '2016-07-22'); insert into sale values(2, 1, 200, '2016-08-22); insert into sale values(3, 2, 300, '2016-09-03'); insert into sale values(4, 2, 400, '2016-10-09'); insert into sale values(5, 4, 500, '2016-11-22'); insert into sale values(6, 4, 600, '2016-12-02');
Sql-Developer
- Statistik aktualisieren:
- Kontextmenü auf Tabelle: "Statistiken erstellen"
- Query-Plan:
- Notepad: "select * from person where ix > 3 and ...;" markieren
- Icon "Explain plan" (F10)