import from branch_1_1:
[freeradius.git] / dialup_admin / sql / oracle / totacct.sql
1 /*
2  * $Id$
3  *
4  */
5
6
7 /*
8  * Table structure for table 'totacct'
9  */
10 CREATE TABLE totacct (
11         totacctid       INT PRIMARY KEY,
12         username        varchar(64) DEFAULT '' NOT NULL,
13         acctdate        DATE DEFAULT sysdate NOT NULL,
14         connnum         NUMERIC(12),
15         conntotduration NUMERIC(12),
16         connmaxduration NUMERIC(12),
17         connminduration NUMERIC(12),
18         inputoctets     NUMERIC(12),
19         outputoctets    NUMERIC(12),
20         nasipaddress    varchar(15) default NULL
21 );
22 CREATE INDEX totacct_acctdate_idx ON totacct (acctdate);
23 CREATE INDEX totacct_nasipaddress_idx ON totacct (nasipaddress);
24 CREATE INDEX totacct_nasondate_idx ON totacct (acctdate, nasipaddress);
25 CREATE INDEX totacct_username_idx ON totacct (username);
26 CREATE INDEX totacct_userondate_idx ON totacct (username, acctdate);
27
28 CREATE SEQUENCE totacct_seq START WITH 1 INCREMENT BY 1;
29
30 /* Trigger to emulate a serial # on the primary key */
31 CREATE OR REPLACE TRIGGER totacct_serialnumber
32         BEFORE INSERT OR UPDATE OF totacctid ON totacct
33         FOR EACH ROW
34         BEGIN
35                 if ( :new.totacctid = 0 or :new.totacctid is null ) then
36                         SELECT totacct_seq.nextval into :new.totacctid from dual;
37                 end if;
38         END;
39 /
40