![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, I modeled a schema for a RDBMS but I am somewhat unsure it the modeling was right. The problems I ran into are that working with my database model and many famous web application frameworks (e.g. Ruby on Rails) is very difficult because they don't seem to be able to handle my data model the way I'd like to (Most of the automatism doesn't work and I have to program a lot of stuff on my own so there is to sense in using these frameworks). However, I'd like to ask you to have a look at my schema and tell me is this is the correct way to model it. My domain is automobile with car dealers, car dealers' garages, gas station, etc. Furthermore I have the following requirements: - I have some car brands (like Ford, GM, Volkswagen, Mercedes, etc.) and the companies dealing with cars (buyers, sellers, garages, gas stations, etc.). - A company can sell cars, buy cars, repair cars, recycle cars, sell gas and do some other things which are not defined yet. - All car brand specific actions like selling, buying, and repairing cars can either by done for all brands or just for specific brands (one or more). For these actions there should also be saved when it started (e.g. Company xyz started selling Mercedes January 10, 2004). My model so far is: Companies (all companies dealing with cars and car related stuff): ID |Name |Street |...|Telephone |... ----------------------------------------------------------------- 1 |Comp ABC |Broadway 1234 |...|+1-212-... |... 2 |Gas XYZ |River Road 12 |...|+1-345-... |... ... Car brands: ID |Name |URL |... ---------------------------------------- 1 |Mercedes |http://www... |... 2 |Volkswagen |... |... 3 |GM |... |... ... Then I have tables for what the companies do with cars: Car buyer: ID |CompanyID |CarBrandID |Since ----------------------------------------------------- 1 |1 |1 |2004-01-20 2 |1 |2 |2005-01-01 3 |2 |3 |1980-01-12 ... Car seller: ID |CompanyID |CarBrandID |Since ----------------------------------------------------- 1 |1 |1 |2004-03-20 2 |2 |3 |1980-02-13 ... Gas station (in fact Gas Brand is a different table referenced from here): ID |CompanyID |Gas Brand |Since ----------------------------------------------------- 1 |3 |Mobil |1980-05-10 ... Does this schema make sense and does anyone have an idea if I can improve it? Thanks, Hilmar |
#3
| |||
| |||
|
|
I modeled a schema for a RDBMS but I am somewhat unsure it the modeling was right. The problems I ran into are that working with my database model and many famous web application frameworks (e.g. Ruby on Rails) is very difficult because they don't seem to be able to handle my data model the way I'd like to (Most of the automatism doesn't work and I have to program a lot of stuff on my own so there is to sense in using these frameworks). However, I'd like to ask you to have a look at my schema and tell me is this is the correct way to model it. My domain is automobile with car dealers, car dealers' garages, gas station, etc. Furthermore I have the following requirements: - I have some car brands (like Ford, GM, Volkswagen, Mercedes, etc.) and the companies dealing with cars (buyers, sellers, garages, gas stations, etc.). - A company can sell cars, buy cars, repair cars, recycle cars, sell gas and do some other things which are not defined yet. - All car brand specific actions like selling, buying, and repairing cars can either by done for all brands or just for specific brands (one or more). For these actions there should also be saved when it started (e.g. Company xyz started selling Mercedes January 10, 2004). My model so far is: Companies (all companies dealing with cars and car related stuff): ID |Name |Street |...|Telephone |... ----------------------------------------------------------------- 1 |Comp ABC |Broadway 1234 |...|+1-212-... |... 2 |Gas XYZ |River Road 12 |...|+1-345-... |... ... Car brands: ID |Name |URL |... ---------------------------------------- 1 |Mercedes |http://www... |... 2 |Volkswagen |... |... 3 |GM |... |... ... Then I have tables for what the companies do with cars: Car buyer: ID |CompanyID |CarBrandID |Since ----------------------------------------------------- 1 |1 |1 |2004-01-20 2 |1 |2 |2005-01-01 3 |2 |3 |1980-01-12 ... Car seller: ID |CompanyID |CarBrandID |Since ----------------------------------------------------- 1 |1 |1 |2004-03-20 2 |2 |3 |1980-02-13 ... Gas station (in fact Gas Brand is a different table referenced from here): ID |CompanyID |Gas Brand |Since ----------------------------------------------------- 1 |3 |Mobil |1980-05-10 ... Does this schema make sense and does anyone have an idea if I can improve it? Thanks, Hilmar That's not a shema, it is a list of data. Obviously you are already working on the physical model (as opposed to the logical model which should be your first step). So show your physical model. IOW, post your DDL for the model: CREATE TABLE statements, constraint statements, etc. We don't have time to reverse engineer the model from your data. |
#4
| |||||
| |||||
|
|
Here are my CREATE TABLE statements (postgresql) including constraints. |
|
CONSTRAINT "PK_company_id" PRIMARY KEY (id), Wrong by the definition of a key!! |
|
CONSTRAINT "FK_company_companymother" FOREIGN KEY (mother_id) REFERENCES companies (id) MATCH SIMPLE |
|
CREATE TABLE CarBrands |
|
the other tables like car_seller, car_repaigarage, ... look like car_buyer. |
#5
| |||
| |||
|
|
4) Have you ever seen a street address that is 254 characters long? NO! The USPS standard is CHAR(35). Most of the other columns also show |
#6
| |||
| |||
|
|
Hi Ed, [] Sorry for just giving an overview over the tables with data. I thought it could be better to show it that way. Here are my create table statements (postgresql) including constraints. There are also some triggers and indexes but they don't add any value to the model I'd like to show. CREATE TABLE companies ( id serial NOT NULL, mother_id integer, name character varying(254), adr_street character varying(254), ... (some more fields) CONSTRAINT "PK_company_id" PRIMARY KEY (id), CONSTRAINT "FK_company_companymother" FOREIGN KEY (mother_id) REFERENCES compoanies (id) MATCH SIMPLE ON UPDATE RESTRICT ON DELETE SET NULL ) CREATE TABLE carbrands ( id serial NOT NULL, name character varying(50), name_full character varying(254), ... (some more fields) CONSTRAINT "PK_carbrands_id" PRIMARY KEY (id), ) [snip] |
|
CREATE TABLE car_buyer ( id serial NOT NULL, company_id integer NOT NULL, carbrand_id integer NOT NULL, since timestamp with time zone, CONSTRAINT "PK_car_buyer_id" PRIMARY KEY (id), CONSTRAINT "FK_car_buyer_carbrand" FOREIGN KEY (carbrand_id) REFERENCES carbrands (id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE, CONSTRAINT "FK_car_buyer_company" FOREIGN KEY (company_id) REFERENCES companies (id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE ) The other tables like car_seller, car_repaigarage, ... look like car_buyer. [snip] |
|
I hope that helps you to help me. Thank you very much, Hilmar |
#7
| ||||||||
| ||||||||
|
|
Here are my CREATE TABLE statements (postgresql) including constraints. This is NOT a relational design at all AND you have done no research. |
|
1) Automobiles are identified by a VIN, which you would have found easily. It is required by law |
|
2) An RDBMS uses keys and not serial numbers!! |
|
3) Columns are NOT fields ; your use of the wrong terms is one reason you cannot get the design right. |
|
4) Have you ever seen a street address that is 254 characters long? NO! The USPS standard is CHAR(35). Most of the other columns also show no research or even a rational guess as to size, defaults or data types. |
|
6) Everything is NULL-able in your world, so you cannot ever have a relational key, DRI, etc. |
|
CREATE TABLE Companies (duns CHAR(9) NOT NULL PRIMARY KEY, -- industry standard code company_name VARCHAR(35) NOT NULL, company_street VARCHAR(35) NOT NULL, .. ); CONSTRAINT "PK_company_id" PRIMARY KEY (id), Wrong by the definition of a key!! |
|
CREATE TABLE CarBrands Did you bother to look up the make and model codes that are industry standards?? They are also in the VIN. A car buyer purchases a particular vehicle : CREATE TABLE Car_Buyers (duns CHAR(9) NOT NULL REFERENCES Companies (duns) ON UPDATE CASCADE ON DELETE CASCADE, vin CHAR(17) NOT NULL REFERENCES Automobiles(vin) ON UPDATE CASCADE ON DELETE CASCADE, purchase_date TIMESTAMP WITH TIME ZONE, PRIMARY KEY (duns, vin)); -- this is the relational key |
#8
| |||||
| |||||
|
|
I have no cars in my database, only the different brands (GM, Ford,Volkswagen, etc.) so I cannot put the VINs in my design as far as I see. |
|
Furthermore I also cannot take just the manufacturer id of the VIN because I can have brands in my database which does not have manufacturers |
|
What do you mean with keys instead of serial numbers? The type "serial" in PostgreSQL is an integer which has an attached sequence. As I don't want to use the names of the car brands as keys I decided to create the generic ids. |
|
Sorry, I took the wrong translation in this case. |
|
As I said above 35 characters are not enough for street names in Germany so I decided not to cut it down in the database. |
#9
| |||
| |||
|
|
On Jan 31, 2:49 pm, Hilmar <newsgr... (AT) silveraxe (DOT) de> wrote: Hi Ed, [] Sorry for just giving an overview over the tables with data. I thought it could be better to show it that way. Here are my create table statements (postgresql) including constraints. There are also some triggers and indexes but they don't add any value to the model I'd like to show. CREATE TABLE companies ( id serial NOT NULL, mother_id integer, name character varying(254), adr_street character varying(254), ... (some more fields) CONSTRAINT "PK_company_id" PRIMARY KEY (id), CONSTRAINT "FK_company_companymother" FOREIGN KEY (mother_id) REFERENCES compoanies (id) MATCH SIMPLE ON UPDATE RESTRICT ON DELETE SET NULL ) CREATE TABLE carbrands ( id serial NOT NULL, name character varying(50), name_full character varying(254), ... (some more fields) CONSTRAINT "PK_carbrands_id" PRIMARY KEY (id), ) [snip] CREATE TABLE car_buyer ( id serial NOT NULL, company_id integer NOT NULL, carbrand_id integer NOT NULL, since timestamp with time zone, CONSTRAINT "PK_car_buyer_id" PRIMARY KEY (id), CONSTRAINT "FK_car_buyer_carbrand" FOREIGN KEY (carbrand_id) REFERENCES carbrands (id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE, CONSTRAINT "FK_car_buyer_company" FOREIGN KEY (company_id) REFERENCES companies (id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE ) The other tables like car_seller, car_repaigarage, ... look like car_buyer. [snip] I hope that helps you to help me. Thank you very much, Hilmar Some how my reply got lost. Since then Joe Chelko has pointed out several places for improvement. I'll just point out one he did not mention. In your car buyer, the constraints do not work. With this design, a buyer can purchase a AUDI PASSAT or a VOLKSWAGEN FOCUS. And given many other tables in your design "look like car_buyer", I expect many other similar problems. |
![]() |
| Thread Tools | |
| Display Modes | |
| |