Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [mysql] MultiDelete, Problem
eai
post
Post #1





Grupa: Zarejestrowani
Postów: 367
Pomógł: 10
Dołączył: 20.05.2005

Ostrzeżenie: (0%)
-----


Witam,
jako że SQL nie jest moją najmocniejszą stroną mam problem z Usuwaniem rekordów z wielu tabel jednym zapytaniem.

  1. DELETE FROM `history`, `thumb`, `photos`, `images`,`group`
  2. USING `history`, `thumb`, `photos`, `images`, `group`
  3. WHERE `group`.`group_id` = 1 AND `images`.`img_group` = 1 AND `history`.`photo_id` = `photos`.`photo_id` AND `history`.`thumb_id` = `thumb`.`thumb_id` AND `photos`.`img_id` = `images`.`img_id` AND `thumb`.`photo_id` = `photos`.`photo_id`;


Problem polega na tym że MySQL nie usuwa żadnych rekordów (nie pokazuje też błędu)
Ten Delete ma usuwać określone pola z tabel:
Kod
`history`, `thumb`, `photos`, `images`,`group`


Tabele wyglądają tak:
group
Kod
group_id | group_name|...

images
Kod
img_id|group_id|...

photos
Kod
photo_id|img_id|...

thumbs
Kod
thumb_id|photo_id

history
Kod
history_id|photo_id|thumb_id|...

Jeśli chodzi o tabelę history w jednej pozycji jest albo photo_id albo thumb_id nigdy jednocześnie

Cała operacja ma wyglądać tak że usuwam wszystko o group_id i kolejno wszystkie rekordy z tych tabel ktore naleza do tej grupy. Group zawiera images, images zawierają photos, photos zawierają thumbs a history zawiera kopie thumbs lub photos.
Kod
group
  |
images
  |
photos  \
  |       history
thumbs  /


Czy da się jednym zapytaniem usunąć rekordy?
Bo robienie kilku selektów i pętl strasznie obciązy serwer.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
eai
post
Post #2





Grupa: Zarejestrowani
Postów: 367
Pomógł: 10
Dołączył: 20.05.2005

Ostrzeżenie: (0%)
-----


Dzięki waszym wskazówkom doszedłem do rozwiązania problemu:

  1. DELETE FROM imagefx_history USING imagefx_history,imagefx_thumb,imagefx_photos,imagefx_images
  2. WHERE imagefx_images.img_group = 1 AND imagefx_photos.img_id = imagefx_images.img_id AND ( imagefx_history.photo_id = imagefx_photos.photo_id OR ( imagefx_thumb.photo_id = imagefx_photos.photo_id AND imagefx_history.thumb_id = imagefx_thumb.thumb_id));


  1. DELETE FROM imagefx_thumb USING imagefx_thumb, imagefx_photos, imagefx_images WHERE imagefx_images.img_group = 1 ANDimagefx_photos.img_id = imagefx_images.img_id AND imagefx_thumb.photo_id = imagefx_photos.photo_id;


  1. DELETE FROM imagefx_photos USING imagefx_photos,imagefx_images WHERE imagefx_images.img_group = 1 AND imagefx_photos.img_id = imagefx_images.img_id;


  1. DELETE FROM imagefx_images WHERE imagefx_images.img_group = 1;


  1. DELETE FROM imagefx_group WHERE group_id = 1;


Niestety muszę wykonać 5 Zapytań. Jestem tylko Ciekaw jak będzie wyglądało obciążenie przy sporej ilości danych....
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 13.10.2025 - 19:31