Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> drzewka for bsp
Jabol
post
Post #1





Grupa: Przyjaciele php.pl
Postów: 1 467
Pomógł: 13
Dołączył: 22.02.2003

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


dobra, mam kod na postgresa i dziala z tym usuwanie bardzo slicznie (IMG:http://forum.php.pl/style_emoticons/default/biggrin.gif)
  1. CREATE SEQUENCE categories_increment
  2. INCREMENT 1
  3. START 1
  4. MINVALUE 1;
  5.  
  6. CREATE TABLE categories (
  7. id BIGINT NOT NULL DEFAULT NEXTVAL('categories_increment'),
  8. parent BIGINT,
  9. name VARCHAR(100) DEFAULT NULL,
  10. UNIQUE (parent, name)
  11. );
  12.  
  13. ALTER TABLE categories ADD PRIMARY KEY (id);
  14.  
  15. CREATE INDEX parent_ind ON categories (parent);
  16.  
  17. ALTER TABLE categories ADD FOREIGN KEY (parent) REFERENCES categories (id) ON DELETE CASCADE;
  18.  
  19. CREATE TABLE asociations (
  20. first_id BIGINT NOT NULL DEFAULT 0,
  21. second_id BIGINT NOT NULL DEFAULT 0,
  22. depth BIGINT NOT NULL DEFAULT 0
  23. );
  24.  
  25. ALTER TABLE asociations ADD PRIMARY KEY (first_id, second_id);
  26.  
  27. CREATE INDEX f_ind ON asociations (first_id);
  28.  
  29. CREATE INDEX s_ind ON asociations (second_id);
  30.  
  31. ALTER TABLE asociations ADD FOREIGN KEY (second_id) REFERENCES categories (id) ON DELETE CASCADE;
  32.  
  33. ALTER TABLE asociations ADD FOREIGN KEY (first_id) REFERENCES categories (id) ON DELETE CASCADE;
  34.  
  35. INSERT INTO categories (parent, name) VALUES (NULL,'sql');
  36. INSERT INTO categories (parent, name) VALUES (1,'postgresql');
  37. INSERT INTO categories (parent, name) VALUES (1,'oracle');
  38. INSERT INTO categories (parent, name) VALUES (2,'linux');
  39. INSERT INTO categories (parent, name) VALUES (3,'sco');
  40. INSERT INTO categories (parent, name) VALUES (3,'linux');
  41. INSERT INTO categories (parent, name) VALUES (7,'windows');
  42. INSERT INTO categories (parent, name) VALUES (6,'glibc1');
  43. INSERT INTO categories (parent, name) VALUES (6,'glibc2');
  44.  
  45. INSERT INTO asociations VALUES (1,1,0);
  46. INSERT INTO asociations VALUES (1,2,1);
  47. INSERT INTO asociations VALUES (1,3,1);
  48. INSERT INTO asociations VALUES (1,4,2);
  49. INSERT INTO asociations VALUES (1,5,2);
  50. INSERT INTO asociations VALUES (1,6,2);
  51. INSERT INTO asociations VALUES (1,7,2);
  52. INSERT INTO asociations VALUES (1,8,3);
  53. INSERT INTO asociations VALUES (1,9,3);
  54. INSERT INTO asociations VALUES (2,2,0);
  55. INSERT INTO asociations VALUES (2,4,1);
  56. INSERT INTO asociations VALUES (3,3,0);
  57. INSERT INTO asociations VALUES (3,5,1);
  58. INSERT INTO asociations VALUES (3,6,1);
  59. INSERT INTO asociations VALUES (3,7,1);
  60. INSERT INTO asociations VALUES (3,8,2);
  61. INSERT INTO asociations VALUES (3,9,2);
  62. INSERT INTO asociations VALUES (4,4,0);
  63. INSERT INTO asociations VALUES (5,5,0);
  64. INSERT INTO asociations VALUES (6,6,0);
  65. INSERT INTO asociations VALUES (6,8,1);
  66. INSERT INTO asociations VALUES (6,9,1);
  67. INSERT INTO asociations VALUES (7,7,0);
  68. INSERT INTO asociations VALUES (8,8,0);
  69. INSERT INTO asociations VALUES (9,9,0);
Zrobile pare przemian. Zmienilem typ na BIGINT oraz pozmienialem nazwy na angielskie. Teraz jeszcze poproboje sie pobawic w przenoszenie :? i takie tam.
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: 22.08.2025 - 23:33