Referential Integrity

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Referential Integrity

    I've got a CONTACTS table that is used to store different
    types of contacts and therefore relates to many different
    tables (CUSTOMERS, SITES,etc). I can EITHER keep a
    relationship with each of this tables, creating columns at
    the CONTACTS table to store each foreign key, OR I can
    keep two columns, REFERENCED_TABLE and
    REFERENCED_TABLE_ID, valid for any related table and then
    manage the referential integrity using triggers. What
    solution do you think is the best ?
    Many thanks, Paulo Weiler
    Paulo Weiler Guest

  2. Similar Questions and Discussions

    1. Integrity constraint violation
      I'm getting the following error when I try to insert the following code: Code: <cfquery datasource="#data_source#"> INSERT INTO...
    2. custom integrity check
      Hi, I have the following table as a link table between my 'cats' table and my 'items' table. Every item must have at least one cat and exactly...
    3. File integrity checkers
      Roberto wrote: Sounds like you need portability and centralized control. Tripwire is the hands down favorite and usually first mentioned,...
    4. Honesty & Integrity = Cash
      Honesty & Integrity = Cash ***I have not tried this yet, but I think it is worth a $7.00 investment. I spend more than that for lunch!*** I'd...
    5. SystemStackError comparing self-referential structures
      irb(main):021:0> a = ; a << a => ] irb(main):022:0> b = ; b << b => ] irb(main):023:0> a == b SystemStackError: stack level too deep I...
  3. #2

    Default Re: Referential Integrity

    Always use Foreign Keys for referential integrity, unless you really need
    the added functionality that triggers can provide. Triggers are a lot slower
    and a more difficult to maintain.

    You can create a script (if you have a good naming convention) to generate
    all the Foreign keys:

    SELECT 'IF EXISTS(SELECT * FROM information_schema.constraints WHERE
    constraint_name = FK_' + c.table_name + '_contacts)'
    + CHAR (13) +
    'ALTER TABLE ' + c.table_name + ' DROP CONSTRAINT FK_' + c.table_name +
    '_contacts'
    + CHAR (13) +
    'ALTER TABLE ' + c.table_name + ' ADD CONSTRAINT FK_' + c.table_name +
    '_contacts'
    + CHAR (13) +
    'FOREIGN KEY (contact_id) REFERENCES contacts (contact_id)'
    + CHAR (13) +
    'GO'
    + CHAR (13)
    FROM information_schema.columns c
    INNER JOIN information_schema.tables t
    ON c.table_name = t.table_name
    WHERE c.column_name = 'contact_id'
    AND c.table_name <> 'contacts'
    AND t.table_type = 'base table'

    Run this in Query Analyzer with 'results in Text'.

    --
    Jacco Schalkwijk MCDBA, MCSD, MCSE
    Database Administrator
    Eurostop Ltd.


    "Paulo Weiler" <europaulo02@yahoo.com> wrote in message
    news:0a3a01c34793$69421950$a101280a@phx.gbl...
    > I've got a CONTACTS table that is used to store different
    > types of contacts and therefore relates to many different
    > tables (CUSTOMERS, SITES,etc). I can EITHER keep a
    > relationship with each of this tables, creating columns at
    > the CONTACTS table to store each foreign key, OR I can
    > keep two columns, REFERENCED_TABLE and
    > REFERENCED_TABLE_ID, valid for any related table and then
    > manage the referential integrity using triggers. What
    > solution do you think is the best ?
    > Many thanks, Paulo Weiler

    Jacco Schalkwijk Guest

  4. #3

    Default Referential Integrity

    Hi

    how to set the referential integrity between 2 tables using enterprise manager (microsoft SQL SERVER).. i tried and the tab doesn't allow me to choose. pls.help.

    thanks
    sree
    weblover Guest

  5. #4

    Default Re: Referential Integrity

    You can do this in 2 ways.

    1. Create a diagram for the db
    Expand the db and double click the diagrams option

    2. Open a table in design mode, right click on a column and select the option
    required from the menu

    Ken

    The ScareCrow Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139