Showing posts with label couple. Show all posts
Showing posts with label couple. Show all posts

Tuesday, March 27, 2012

Database Help

Hi,

I have a question about setting up a couple of database tables.

I'll try to explain using an example:

We have a customer (stored in a customer table)

CustomerCode: JDOE (Primary Key)

CustomerName: John Doe

Address: 123 Cherry Lane

City: Dubbo

State: NSW

PostalCode: 2830

Who was sent an invoice for an order he placed. That invoice was sent to his current address at the time (123 Cherry Lane).

Let’s say he moved to a new address. We would update his customer record accordingly.

CustomerCode: JDOE (Primary Key)

CustomerName: John Doe

Address: 987 Apple Road

City: Dubbo

State: NSW

PostalCode: 2830

Now, let’s say that we want to be able to look back at JDOE’s invoices and see where they were shipped too. This means we have to store that address somewhere.

Now if we said just store it on the invoice table like:

InvoiceNo: 0001 (Primary Key)

CustomerCode: JDOE (Foreign Key)

Address: 123 Cherry Lane

City: Dubbo

State: NSW

PostalCode: 2830

Amount: $300.00

That would break 3rd normal form as the address doesn’t depend on the primary key (InvoiceNo [0001]).

We want to be able to see the address from the invoice table via a relationship/lookup/computational column/whatever.

How would we go about doing this in SQL Server version 8?

Cheers,

Pete

I think it is pretty common to have a set up like that. So you might have have a table(s) that lists default values for customers and an actual invoice table that includes actual ship address. You can divide it up for storage and performance reasons as necessary but most companies need to have that historical info available.

My two cents :-)

|||

Hi,

You can have an additional column say address2 for the current address. I know this sounds naive, but sometimes this is the best way to get things done. Now you may ask, what if I have more than 2 addresses, then boy ur going to have a tough time coming up with a schema, which stores historical information.

Good Luck and let me know, how u went about it.

PP

|||

G'day,

Not be blunt, but the above suggested example is very poor design. One particular (and there are several) solutions to this is to first separate the address details from the customer details:

Customer Table

CustomerCode, CustomerName,

Address Table

CustomerCode, AddressID, Addresstype, line1, Line2, PostCode,State

This will then allow a customer to first of all have more then 1 address recorded (physical, postal, work, home etc) as well as almost conforming to 3NF (the State column would in fact need to become a "StateID" column lookup into a "State' table...).

Or, if you really didn't want to store multiple addresses, just keep your same design and create a trigger on the customer table to record any address details that change into a seperate table (example only):

CREATE TRIGGER CustomerAddress_upd

on CustomerTable AFTER UPDATE

AS

BEGIN

IF ( UPDATE(Line1) OR UPDATE(PostCode) ) --list all required cols here

BEGIN

INSERT INTO AddressAudit (CustomerCode, Line1, PostCode, DateChanged)

SELECT CustomerCode, Line1, PostCode, getDate()

FROM CustomerTable c

JOIN Inserted i ON c.CustomerCode = i.CustomerCode

END

END

Then, if required, just query the audit table.

Cheers,

Rob

sql

Thursday, March 22, 2012

Database files (VS 2005) - usage?

I'm just getting to grips with the new SQL Database file concept in VS 2005
and have a couple of questions in the hope that someone can clarify my
understanding.
I understand that I can now add both the <dbname>.mdf and <dbname>.ldf files
traditionally associated with a SQL Server into my application folder, and
that these are attached to SQL Express at runtime. I see this an ideal
replacement for an Access database on single user desktop applications,
leveraging the power of a SQL Server whilst offering the advantages of a
file-based db like Access (x-copy backups for example).
However, for a small multi-user system (say 5 users), am I right in thinking
that the database is now shared and therefore the database files need to be
available to all users on a network share? It seems obvious, but then does
each user attach these shared files to their local SQL Express, or is there
one application / SQL Express nominated as the 'server' with the remaining
applications running in a pure 'client' mode? And if the latter, how is the
connection string managed?
Am I barking up the wrong tree with this?
CheersAndrew Kidd wrote:
> However, for a small multi-user system (say 5 users), am I right in thinki
ng
> that the database is now shared and therefore the database files need to b
e
> available to all users on a network share?
No. The database files just need to be visible to the server. In fact
it's probably a good idea to make sure that user's can't see the
network share where the database resides.

> It seems obvious, but then does
> each user attach these shared files to their local SQL Express, or is ther
e
> one application / SQL Express nominated as the 'server' with the remaining
> applications running in a pure 'client' mode? And if the latter, how is th
e
> connection string managed?
>
One server. Multiple clients. The clients don't need Express they just
need SQL Server connectivity: Native Client or MDAC.
David Portas
SQL Server MVP
--|||Thanks David.
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:1133528080.622239.309940@.o13g2000cwo.googlegroups.com...
> Andrew Kidd wrote:
> No. The database files just need to be visible to the server. In fact
> it's probably a good idea to make sure that user's can't see the
> network share where the database resides.
>
> One server. Multiple clients. The clients don't need Express they just
> need SQL Server connectivity: Native Client or MDAC.
> --
> David Portas
> SQL Server MVP
> --
>|||When would a department, with say only 5 users and < 2GB of data, want to
move from using SQL Server Express to Workgroup Edition?
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:1133528080.622239.309940@.o13g2000cwo.googlegroups.com...
> Andrew Kidd wrote:
> No. The database files just need to be visible to the server. In fact
> it's probably a good idea to make sure that user's can't see the
> network share where the database resides.
>
> One server. Multiple clients. The clients don't need Express they just
> need SQL Server connectivity: Native Client or MDAC.
> --
> David Portas
> SQL Server MVP
> --
>|||JT wrote:
> When would a department, with say only 5 users and < 2GB of data, want to
> move from using SQL Server Express to Workgroup Edition?
>
When they need the scalability or functionality of one of the other
editions:
http://www.microsoft.com/sql/prodin...e-features.mspx
David Portas
SQL Server MVP
--