home *** CD-ROM | disk | FTP | other *** search
/ MACup: Giveaway 1996 / Image.iso / Shareware & Demos / Web-Publishing / SNAP PrimeBase / Telephone & Tabler / CreateDB < prev    next >
Encoding:
Text File  |  1996-07-14  |  2.6 KB  |  102 lines  |  [TEXT/ttxt]

  1. integer totalcalls = 25;
  2. integer currcall = 5;
  3.  
  4. declare procedure progress(message)
  5. argument varchar message;
  6. {
  7.     currcall++;
  8.     print $progress, currcall*100/totalcalls, $format("Creating Telephone Database:\r")+message, 0;
  9. }
  10. end procedure progress;
  11.  
  12. progress("One moment please...");
  13. create database :DatabaseName;
  14.  
  15. progress("Opening the database...");
  16. open database :DatabaseName;
  17.  
  18. progress("Domain: NameType");
  19. CREATE DOMAIN Common.NameType VARCHAR(64) order as case insensitive;
  20.  
  21. progress("Domain: DeptCode");
  22. CREATE DOMAIN Common.DeptCode INTEGER;
  23.  
  24. progress("Domain: TypeCode");
  25. CREATE DOMAIN Common.TypeCode INTEGER;
  26.  
  27. progress("Domain: PersonID");
  28. CREATE DOMAIN Common.PersonID INTEGER;
  29.  
  30. progress("Table: Department");
  31. CREATE TABLE Common.Department
  32. (
  33.     Code        DeptCode        NOT NULL,
  34.     Name        NameType
  35. );
  36. progress("Primary Key on Department");
  37. CREATE PRIMARY KEY    Common.DepartmentPk    ON Department.Code;
  38. CREATE INDEX Common.iDepartment ON Department(Code);
  39.  
  40. progress("Table: Type");
  41. CREATE TABLE Common.Type
  42. (
  43.     Code        TypeCode        NOT NULL,
  44.     Name        NameType
  45. );
  46. progress("Primary Key on Type");
  47. CREATE PRIMARY KEY    Common.TypePk    ON Type.Code;
  48. CREATE INDEX Common.iType ON Type(Code);
  49.  
  50. progress("Table: Person");
  51. CREATE TABLE Common.Person
  52. (
  53.     ID            PersonID        NOT NULL,
  54.     Name        NameType,
  55.     Surname        NameType,
  56.     Department    DeptCode
  57. )
  58. progress("Primary Key on Person");
  59. CREATE PRIMARY KEY    Common.PersonPk        ON Person.ID;
  60. CREATE INDEX Common.iPerson ON person(ID);
  61. progress("Foreign Key: Person -> Department");
  62. CREATE FOREIGN KEY    Common.PersonDeptFk    ON Person.Department;
  63. CREATE INDEX Common.iNameSurname ON person (name, surname);
  64. CREATE INDEX Common.iSurname ON person (surname);
  65.  
  66. progress("Table: Department");
  67. CREATE TABLE Common.Number
  68. (
  69.     Person        PersonID        NOT NULL,
  70.     Type        TypeCode        NOT NULL,
  71.     Number        VARCHAR(64),
  72.     Key            (Person, Type)
  73. );
  74. progress("Primary Key on Department");
  75. CREATE PRIMARY KEY    Common.NumberPk            ON Number.Key;
  76. CREATE INDEX Common.iNumber ON Number(Key);
  77. progress("Foreign Key: Department -> Person");
  78. CREATE FOREIGN KEY    Common.NumberPersonFk    ON Number.Person;
  79. progress("Foreign Key: Department -> Type");
  80. CREATE FOREIGN KEY    Common.NumberTypeFk        ON Number.Type;
  81. CREATE INDEX Common.iTypePerson ON Number (Type, Person);
  82.  
  83. progress("Inserting empty department...");
  84. INSERT Department VALUES (1, "-");
  85.  
  86. progress("Inserting default number types...");
  87. INSERT Type VALUES (1, "Work");
  88. INSERT Type VALUES (2, "Extension");
  89. INSERT Type VALUES (3, "Home");
  90. INSERT Type VALUES (4, "Mobile");
  91.  
  92. progress("Inserting a dummy number...");
  93. INSERT Person VALUES (100, "John", "Doe", 1);
  94.  
  95. INSERT Number VALUES (100, 1, "12345");
  96.  
  97. progress("Completed successfully");
  98.  
  99.  
  100.  
  101.  
  102.