Re: How to desgin version control & primiary key ?
From: Adam Machanic (amachanic_at_hotmail._removetoemail_.com)
Date: 10/31/04
- Next message: Kevin_at_test.com: "Re: question on HAVING"
- Previous message: Adam Machanic: "Re: question on HAVING"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 31 Oct 2004 10:15:06 -0500
"Agnes" <agnes@dynamictech.com.hk> wrote in message
news:umALmXvvEHA.1524@TK2MSFTNGP09.phx.gbl...
>
> I got an InvoiceTable with the primary key Invno, InvoiceChgtable will
keep
> the charges , noofunit, unitpirce.. etc, its primary key is using
'smallint'
> with increment YES
Are you certain this will give you enough space to store all of the
changes over a long period? Why not use an INT instead? The SMALLINT will
only give you 32767 possible rows in the table; you'll use that up more
quickly than you think.
> 1) Should I use store procedure to insert the previous verson data or
> trigger rule ?
> If using trigger rule ? How can I do that ? (I never use trigger
> before )
I would recommend using a trigger to handle this situation. The reason
is that you may require different stored procedures for various business
logic, and if you need to record history from each stored procedure that
will mean that you'll have to duplicate the logic across all of your
procedures. However, with a trigger you'll be able to centralize the logic
in one place. You should look up CREATE TRIGGER in Books Online and review
the syntax; they're not too difficult to use... What you'll do is create a
trigger FOR UPDATE that inserts all of the rows from the virtual 'deleted'
table (which appears within every trigger) into your history table.
> 2) If I want to keep the prevoius verson , How should I design the primary
> in invoiceTable ?? Invoiceno with suffix? such as (INV0001-XX) XX is the
> version ??
Why would you want to store the version number in the invoice table?
Does the version number matter for your business logic?
> 3) for some other tables, I got 3-relationship , parent , child and
> grandchild, I got no idea how to design the primiary key in grandchild .
Please post DDL for those tables. (
http://www.aspfaq.com/etiquette.asp?id=5006 )
-- Adam Machanic SQL Server MVP http://www.sqljunkies.com/weblog/amachanic --
- Next message: Kevin_at_test.com: "Re: question on HAVING"
- Previous message: Adam Machanic: "Re: question on HAVING"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|