Avatar billede morphman Nybegynder
08. maj 2005 - 16:38 Der er 45 kommentarer og
1 løsning

Database Design

Well, I don't know where to start. However, here it goes. I am tryin' to make a database for a online shopin' cart (which by the way is a school project of mine) I need make this shopin' cart in c++ and mySQL, I havn't had much me hands in mySQL, quite frankly I never have (yet we have make the database in mySQL). But, back to the matter of discussion, If it's not much of a hustle I hopin' that ye might me of some help to me *as ye have been previously*

I've got the database design and the ClassDiagram I don't know if that would be of any help. However here are the url's:

http://img.photobucket.com/albums/v214/morphmanaf/dbdesign.jpg
http://img.photobucket.com/albums/v214/morphmanaf/Classdesign.jpg

I know this doesn't contain all the thing a pro. shopin' cart should include. Well, this isn't a pro. cart. It's should only be able to preform the esstinal tasks. Nevertheless, ye are more than welcome to add a few things'

ps: if it's of any help I could also provide ye with me fatal atempt at mySQL (the SQL file)
Avatar billede arne_v Ekspert
08. maj 2005 - 16:45 #1
What is the problem ?

It should be relative easy to create the necesarry tables in MySQL.

What API are you using for C++ -> MySQL ?

Regarding the design then you have choosen to map the clas hierachy to 1 database
table. You could also have choosen 2 tables or 3 tables. But of you are
comfortable with your choice, then it is fine.
Avatar billede morphman Nybegynder
08. maj 2005 - 16:51 #2
Well, I am currenly usin' MYSQL Borland C++ API.
There is is nothin' wrong with the database I just can't seem to get the primary keys to link. Could help me out here?
Avatar billede arne_v Ekspert
08. maj 2005 - 16:53 #3
You mean foreign keys and referential integrity ?
Avatar billede morphman Nybegynder
08. maj 2005 - 16:59 #4
Yeah..
Avatar billede arne_v Ekspert
08. maj 2005 - 17:01 #5
Note that MySQL supports several table formats.

The default format MyISAM does not support foreign keys and referential integrity.

InnoDB tables do.
Avatar billede arne_v Ekspert
08. maj 2005 - 17:01 #6
Also note that MySQL has some restrictions about fields and indexs when
using foreign keys.

Have you read the docs ?
Avatar billede morphman Nybegynder
08. maj 2005 - 17:03 #7
I don't really know which I am I usin' however, here's what I got till now. By the way, how can I check which format it is?
Avatar billede morphman Nybegynder
08. maj 2005 - 17:03 #8
Avatar billede arne_v Ekspert
08. maj 2005 - 17:05 #9
no explicit tabel format => default tabel format => MyISAM

CREATE TABLE xxx (
...
) TYPE=InnoDB;
Avatar billede morphman Nybegynder
08. maj 2005 - 17:08 #10
Ahh..okay. So I guess, I'll have to put "TYPE=InnoDB" in the end of every table I create..right?

But what about the rest of the database does it seem to be okay?
Avatar billede arne_v Ekspert
08. maj 2005 - 17:09 #11
yep
Avatar billede arne_v Ekspert
08. maj 2005 - 17:10 #12
I have mentioned the class hieirachy O-R mapping issue. That is the only one
I took note of.
Avatar billede morphman Nybegynder
08. maj 2005 - 17:11 #13
Can I also use this "ENGINE=InnoDB" insted of the "TYPE=InnoDB"?
Avatar billede arne_v Ekspert
08. maj 2005 - 17:12 #14
I belive so
Avatar billede morphman Nybegynder
08. maj 2005 - 17:15 #15
Okay, but could ye please check; if it's not much to ask, if the database design diagram is equal to the end product the SQL file...Cause that would be a real helpful thing...thanx :)
Avatar billede arne_v Ekspert
08. maj 2005 - 17:18 #16
It is not !
Avatar billede morphman Nybegynder
08. maj 2005 - 17:20 #17
Why not, what wrong? It's not in a good way or in a bad way?
Avatar billede arne_v Ekspert
08. maj 2005 - 17:20 #18
table kunde

design : field navn
SQL : fields fnavn,enavn

design : no city
SQL : city
Avatar billede arne_v Ekspert
08. maj 2005 - 17:20 #19
the first may be good
the second is bad
Avatar billede arne_v Ekspert
08. maj 2005 - 17:21 #20
in the design you have mapped the class hierachy to 1 table but in the SQL it
is mapped to 3 tables

both are valid

but they should be consistent
Avatar billede arne_v Ekspert
08. maj 2005 - 17:22 #21
pris should probably not be INT but DECIMAL instead
Avatar billede morphman Nybegynder
08. maj 2005 - 17:28 #22
Now that's what's I am talkin' about. See I knew there was somethin' wrong.
Since I am runnin' pretty busy with C++ programmin', So, I am askin' ye if ye could please make the so called good changs to the database I would be really thankful...thanx :)
Avatar billede arne_v Ekspert
08. maj 2005 - 17:39 #23
the good change is just removing the city field from all tables except the
city table
Avatar billede morphman Nybegynder
08. maj 2005 - 17:46 #24
he he...okay....and what do I need to do, if I want the table called person which contains the esstinal stuff which both the "ansat" and the "kunde" share and the two other tables called "kunde" and "ansat" which got the thing which they don't have in common..if ye catch me drift.
Avatar billede arne_v Ekspert
08. maj 2005 - 17:53 #25
you can map a class hirachy like this to tables in 3 ways:

1 table with all the fields from all classes
2 tables one for each concrete class with all fields for this including inherited
3 tables on for each class with the same primary key used as foreign keys in sub classes

In the design you used the first.

In the SQL you used the last.

Both are fine, but design and SQL should match.

And I think are missing a field in the 2 sub class tables: BRUGERID
Avatar billede arne_v Ekspert
08. maj 2005 - 17:54 #26
I assume that the first table KUNDE is just a duplicate og PERSON
and should not be considered
Avatar billede morphman Nybegynder
08. maj 2005 - 18:04 #27
I see..I am makin' a new db now..perhaps this time it'll be consistent with the design state:

But, please can't ye make a db which looks like the class design? Please?
Avatar billede arne_v Ekspert
08. maj 2005 - 18:10 #28
You do not learn from me doing it !

:-)
Avatar billede morphman Nybegynder
08. maj 2005 - 18:17 #29
he he...that's why I am makin' it too...I just need somethin' to look at a reffernce if ye may ;)
Avatar billede morphman Nybegynder
08. maj 2005 - 18:22 #30
Avatar billede morphman Nybegynder
08. maj 2005 - 18:27 #31
wwoops..I forgot the city :)
Avatar billede arne_v Ekspert
08. maj 2005 - 18:28 #32
It looks good.

Some comments.

What is person TYPE ?

Consider using different max lengths than 45 f.ex. POSTNR will never be that long.

vare BRUGERID should that not be INT like the field it is referring to ??

I still think VARE PRIS hsould be DECIMAL(10,2) or something like that
Avatar billede morphman Nybegynder
08. maj 2005 - 18:32 #33
You are indeed right the format is surely suppose to be DECIMAL, INT and ect. However, I just made it like this since it's a test ;)

As for the TYPE field I was thinkin' if it could be a TRUE/FALSE field then one could set ture if it's a "kunde" false if not...see what I mean?
Avatar billede morphman Nybegynder
08. maj 2005 - 18:35 #34
Well, that's currently not me main concern. Me main concern is the referential integrity. *are the keys pointin' to the right things*
Avatar billede arne_v Ekspert
08. maj 2005 - 18:58 #35
It would not be true relational to have a TYPE field to specify that.

(but it may still be practical)
Avatar billede morphman Nybegynder
08. maj 2005 - 19:01 #36
I see..So, how do one make a true false field in mySQL? Default value of FALSE?
Avatar billede arne_v Ekspert
08. maj 2005 - 19:22 #37
you dont

:-)

TINYINT med 0 eller 1 (BIT og BOOLEAN er synonymer for TINYINT)

eller

ENUM('True','False')
Avatar billede morphman Nybegynder
08. maj 2005 - 19:40 #38
Ohh..okay I see...so I can just do like this:

MODIFY COLUMN 'TYPE' TINYINT UNSIGNED NOT NULL DEFAULT 0;
Avatar billede morphman Nybegynder
08. maj 2005 - 19:45 #39
MODIFY COLUMN `TYPE` ENUM('TRUE', 'FALSE') NOT NULL DEFAULT FALSE;

right`?
Avatar billede morphman Nybegynder
08. maj 2005 - 19:47 #40
But I can't seem to set a DEFAULT on it..why is that?
Avatar billede arne_v Ekspert
08. maj 2005 - 19:57 #41
MODIFY COLUMN `TYPE` ENUM('TRUE', 'FALSE') NOT NULL DEFAULT 'FALSE';

måske
Avatar billede morphman Nybegynder
08. maj 2005 - 20:16 #42
ahhh...yes, that's right ;)

http://i.domaindlx.com/morphman/eksperten/spm/616064/test2.sql

but this referential integrity thing is givin' me grey hair ;)
Please help me with that..I 've removed all the referential links. :(
Avatar billede morphman Nybegynder
09. maj 2005 - 08:39 #43
Guess, ye don't have time for that...well...what can I do....thanks for ye help.
please anwser if ye want ye points, mate *thank ye very much for ye time*
Avatar billede arne_v Ekspert
09. maj 2005 - 10:46 #44
I am not sure what you expect from me. You can add the constraints, try execute the SQL
and see if it works. If it does not, then check the SQL statements and if
it does not reveal anything then post the CREATE TABLE statements and the
error text here - and we will look at it.
Avatar billede arne_v Ekspert
09. maj 2005 - 10:46 #45
svar
Avatar billede morphman Nybegynder
09. maj 2005 - 20:51 #46
Well, okay, I'll give it one more shot *but if that doesn't work I hope ye can make all the referential links in this database*
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Computerworld tilbyder specialiserede kurser i database-management

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester