Im developing a Car Classifieds but im not sure of how is the best way to design something, there are some features of cars like if it have 2,4 doors, if it is 4x4 or 4x2, engine 1.6, 2.0.
All this features are particular for a car but they have to be limited to what that mode have, so each time someone is posting a bike for example it would not show the option in a drop-down for 4x4, or engines than that model.
I don't want to make this generic, it would only work for cars, so thinking in how it would be best for generic classifieds its not necessarily.
What would be the best way to design this?
More Info:
My problem is how to design the relation between a Car Model and a actual car, for example the Year of a Model could go from 1990-2000, when someone is going add a Car of that model i only want them to be able to choose from the options that model have. How do i store this in a database?
You need to differentiate between a car model instance ("my car vin xxx") and a car model specification ("2009 Mazda 3"). In general a model spec has a model number and a model instance has a serial number (the VIN in this case).
You also need to differentiate between the available options for a model spec and the actual installed options for a model instance.
/* the model specifications: */
vehicle_model
id
model_name
from_year
to_year (nullable)
manufacturer_id
/* engine specifications */
engine
id
name (ex. "Cummings Turbo Diesel")
...
/* available engines for a model. you would use this table to show only the appropriate engines for a given model spec */
vehicle_model_engine
model_id
engine_id
/* vehicle instances: */
vehicle
id
vin
model_id FK vehicle_model
engine_id FK engine
You could either put a multi-column foreign key from vehicle(model_id, engine_id) to vehicle_model_engine(model_id, engine_id), or just put a single key to engine(id) and use application logic to check before saving.
I work at an automotive company, and I would recommend starting with year, make, model and trim. All cars have these values. You can hardcode those into a database structure.
Beyond that, just make an attribute table that will have those additional attributes.
Don't bother trying to make fields specifically for engine, number of doors, etc. You'd be surprised that some cars have more than one engine (!).
Tables for YMMT and attributes:
Vehicle
vehicle_id int not null (auto increment),
year int,
make varchar(100),
model varchar(100),
trim varchar(100)
Vehicle_Attribute
vehicle_id int,
attribute_name varchar(100),
attribute_value varchar(100)
Related
I started building a database to manage things like vehicles, finances, bills, work history, residence history....etc.
I'm mostly doing this as a learning exercise to teach myself different methods of schema design and ground up development. I've been a database developer for 4 years, but I've only ever worked on the same system/schema. Even my ground up development of new features still have to abide by the existing Schema.
Anyways, I have tables for things like Vehicle Registration, Vehicle Loans/Purchases, Bills, etc. But rather than storing their billing info (payment amount, occurrence, etc), I thought maybe I could put a GUID column on every table, and then store the billing info by the GUID, and then have some sort of view or function that lets me look up the object_id (table) for a particular GUID.
Is this design method a good way to do things?
How would I go about designing the function/view to return the objectid / tablename for specific GUID's?
EDIT: I guess this is a poor explanation, so here's a quick example:
Table: VehicleRegistration
This table would have information like license plate, when the registration is good for, etc.
Table: VehicleLoan
This table would have loan information about each vehicle (amount financed, term, apr, date of purchase, etc).
Both of those tables would also have information like Billing Date, Occurence, Estimated Amount, etc. But instead of storing that data in the two tables, I would store it in another table called BillingInfo or something like that. Obviously I could add a FK on the two tables that point to the PK on the BillingInfo table. But that would mean every table that requires billing information would require that FK on it. Rather than creating that FK on every table...what if instead, every row in VehicleRegistration and VehicleLoan had a unique ID. And I would store the billing info by unique ID instead.
And since it's unque across tables, I would have a function or view to tell me which table that GUID is in. (keep in mind, this is a very small personal database, so for now, speed and optimization is not a concern).
If I applied this method to all common info, like billing information, then I could avoid having to put a FK on every table that needs it. I could just create the table and use the Unique ID's instead?
I am making an application that will process a big chunk of information. This information was retrieved using some web crawlers and is about news, containing data such as News Title, URL, Publication Date, Category and Content. The crawled data is in XML format, and I will load that information into my application.
From there, 10 users will process every news and tag the category of the news manually by reading the title. I've used 9 main categories to be used, and for each news the users will decide from 0-5 how much this particular news belongs to each category.
Users will also search for news by title and decide if this news is discussing the same event as another news, or if this news is similar to another news (like a news about a football game at 3 PM and a news about a football game at 5 PM).
I have no problems with making the application itself, I just need some help with the part of how to design one/many tables that can link news that talk about similar events or about the same event, since there can be many many news that can talk about the same event.
So far I've done something like this:
Table News
ID
Title
URL
PublicationDate
NewsContent
Table Category
NewsID
User_ID
Economy
Politics
Present_Day
Sport
Technology
Showbiz
Culture
Region
World
Table User
ID
FirstName
LastName
Each category field in the Category table holds a tinyint data type (I'm using SQL Server) and I've restricted the values the user can input via a check constraint so that it allows values from 0 - 5. I don't know if this is the right approach so far for the database design, and I need to add the table/s that allow to add information about similar news or news that talk about the same event, such as a table Similar_News containing some fields like News_ID, SimilarNews1_ID, SimilarNews2_ID and so on, and must contain the information about which user 'said this', but this sounds like a flawed design to me.
Any help is appreciated, thank you.
Here are some suggestions. In the CATEGORY table you have created 9 different columns (economy, politics etc). What if a few days / months / years down the line there is a new category. In this case you will have to modify your database design. Instead, you could have the following structure of your CATEGORY table.
CategoryId
Category
And have one more table to store the actual news categorization.
Table: NewsCategory
NewsId
CategoryId
CategoryWeight (This will store the rating from 1-5)
If the user feels that a news does not belong to a particular category then no row will be inserted in this table for that category. Such a structure will give you more flexibility to insert new categories in future without changing the database design. You just have to insert new rows in the Category table.
For storing similar news I would recommend one of the following approach.
Create a table event and store the details of the event in this table.
EventId
EventDescription
Sample Data
EventId: 55
EventDescription: Euro 2016 Belgium vs Italy
Now you can include this EventId in your News table. This way you can pull up all the news that are related to this event.
Create Similar_News table with n fields to store the similar News_Id doesn't sound a good idea. How many fields would you create? 3? 10?
You are modeling a n to m relationship so I would only use two fields (three if you wanna store the User Id). For example if New 1 is similar to news 2 and 3. And New 3 is similar to 4, you insert the rows:
New_ID SImilar_New_Id
--------------------------
1 2
1 3
3 4
Another approach would be use a NOSQL DB to store flexible structures, for example:
"News":{
"User_Id":1,
"Category"{
"Economy":3,
"Politics":4
},
"Similar_News":[1,2,3]
}
According to my design I have car models(BMW, toyota, ...) and car types(coupe, sedan, van, ...). So my CAR table has those two tables primary key and price information.
My problem is that I have one more car type named "customizable". that car type dont have an exact price because its open for bargain. I mean a coupe BMW's price is always same like sedan BMW but customizable BMW varies.
Current design doesnt meet that need. How can I solve this.
It sounds like you need to store the negotiated price against the Allocation - since that's the table that has the Car and Customer in it.
Or you could add another table which gets queries when the Type is 'custom'.
As a personal project, I essentially want to create a web application that allows users to submit amplifier settings for specific tones, which will render images and create an archive of guitar tones for specific amps.
I know that I first should design a database to support this web application. After reading about relational databases and normalization, I have started to draft a database, but I've confused myself in the process.
So far, I've created the following tables:
tbl_Makes (list of amplifier brands):
tbl_Models (list of amplifier models, linked to their brand by the MakeID field):
But I am at a bit of a loss on how to design the remaining table(s). I assume I will need a tbl_Settings table which contains both MakeID, and ModelID as foreign keys, but also some sort of column(s) to hold the amplifier settings. The issue I'm currently facing is that most amplifiers have different settings, so I'm not sure how I'd handle that. Would I need an additional table for each amplifier model to hold its specific settings?
Any suggestions? Is my current database design ok, or does it need to be modified?
You may be breaking it down too far. A table with Make and Model may be good enough. However with your current design, you would make the MakeID a Foreign Key to the Make table's Primary Key (ID).
Then you'd have an "settings" table which has a ModelID, attribute, and value - since each AMP may have different attributes. You may want to have an attribute table and use attributeID if you want to control the attribute types (with a PK and FK relationship).
Oh, and for the love of God, please don't prefix tables with tbl_
I am building an e-shop that will have configurable products. The configurable parts will need to have different prices and stocks from the main product.
What database design would be best in this case?
I started with something like this.
Features
id
name
Features Options
id
id_feature
value
Products
id
name
price
Products Features
id
id_product
id_feature
value ( save the value from the feature-options for ease in search )
configurable (yes, no)
The problem is that now I am stuck on how to save the configurable product features.
I was thinking of saving their value as a json. But that will make saving price modification for a certain option difficult.
How would you go about this ?
Thank you.
Two more tables will do the magic (below). Hacks like JSON or parseable text fields can and should always be avoided.
-- one product <id_product> can have multiple
-- product variants <id> with different features enabled
product_variant
id
id_product (one product - many variants)
-- features, enabled for certain <id_product_variant>
product_variant_enabled_feature
id
id_product_variant (one variant - many features)
id_product_feature
unique_constraint(id_product_variant, id_product_feature)