Advertisement
techmoz

Untitled

Aug 13th, 2011
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.14 KB | None | 0 0
  1. SET term ^;
  2.  
  3. CREATE TABLE %tablename%
  4. (  
  5.   %tableprefix%_id_%tablename%           INTEGER        NOT NULL  
  6. , %tableprefix%_bla                      INTEGER    
  7. , %tableprefix%_id_client                INTEGER
  8. , %tableprefix%_history                  BLOB sub_type text
  9. , %tableprefix%_report                   BLOB sub_type 0  
  10. , %tableprefix%_report_compression_type  d_compression_type
  11. , %tableprefix%_report_compressed_size   INTEGER
  12. , %tableprefix%_report_uncompressed_size INTEGER
  13. , CONSTRAINT uq_%tableprefix%_bla            UNIQUE(%tableprefix%_bla)
  14. , CONSTRAINT fk_%tableprefix%_id_client      FOREIGN KEY (%tableprefix%_id_client)  REFERENCES client (cl_id_client)
  15. , CONSTRAINT pk_%tableprefix%_id_%tablename% PRIMARY KEY (%tableprefix%_id_%tablename%)
  16. ) ^
  17.  
  18. CREATE generator gen_%tableprefix%_id_%tablename% ^
  19. SET generator gen_%tableprefix%_id_%tablename% TO 0 ^
  20.  
  21. CREATE TRIGGER %tablename%_gen
  22.        FOR %tablename%
  23.        active BEFORE INSERT
  24. AS
  25. BEGIN
  26.   IF (NEW.%tableprefix%_id_%tablename% IS NULL) THEN BEGIN
  27.     NEW.%tableprefix%_id_%tablename% = gen_id( gen_%tableprefix%_id_%tablename%, 1 );
  28.   END
  29. END
  30. ^
  31.  
  32. SET term ;^
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement