I'm creating a simple database which will allow users to manage cars and contains data like registration number, brand, model, dates of upcoming maintenance controls... (in my country marka = brand)
I have created relations like this:
In t_podwozie I have created link & relation columns fk_marka, fk_model. I need fk_model choices to be limited by my choice in fk_marka.
I have tried to use a query connecting brands and model (INNER JOIN) but then I can save only one column in t_podwozie. Any advice?
Both link & relation columns consist of id column and name column (id's are hidden)
Related
I'm trying to model a database for facebook users. For my User table I have {account_name, account_id, ..., password} as variables. I'm trying to create a table for friends of that user, such as a Friendlist or Contacts table, but I'm wondering would the contacts table have to have a list of all the possible friendships (i.e. {user_id, friend_id, friends_since,...} ) or is it possible to have the contact table specific to a certain user_id (so {contact_id, friends_since, no_of_mutual_contacts, etc..}).
This is probably just the object orientated part of my brain coming into action, but say for example if we were using a Cinema database. There were 5 cinemas and each had 5 screens, CINEMA is a table and SCREEN is a table. Would the SCREEN table have 25 instances of data or is there some way that the SCREEN table would only contain the 5 screens corresponding to a specific CINEMA.
This comes back to my original question, would the Contacts table have to be a global table containing all friendships, or does the Contacts table only return the contacts specific to the user_id.
For some reason when I'm looking at the relational chart of the database I see the connections ressembling a somewhat object like structure where the links are just denoted members like user.Contacts or user.Events.
Normally a table in a relational database will record all facts of a given type, e.g. user <user_id> is friends with user <friend_id> since <friends_since>.
You can create views for given users if required, or just specify a user_id in your queries, to get the subset of rows applicable to a specific user.
Creating a physical table specific to certain users would create difficulties if you wanted to get all the rows for a certain friend_id.
I have a database design here: I want to add a LIST of Products selected by a Customer into purchase table->product column.
How should i define the attributes in "localhost/phpmyadmin" so that the column can hold multiple value?Here say i want to store multiple product id in product_id column. How should i define the schema attributes?
I have the following 3 tables:
Retailers - ID, Name
Registration - ID, Status (YES/NO)
Refund - ID (populated into a dropdown list from Retailers table), Name (Empty), Status (Empty)
Retailers is a table full of data, while Refund starts off as an empty table that gets filled in as a Refund Form is filled up. After creating a form based on the Refund table, how do I allow a user to select an ID from the dropdown list and populate the corresponding Name into the Name field and Status into the Status field?
What are the queries needed and how do I integrate this into the form?
I have tried the method found here - https://www.linkedin.com/pulse/autofill-form-microsoft-access-tim-miles
However, I have run into 2 problems:
1) The form does not appear in "Form View"; it is only viewable in layout view. I have read many links saying that the queries are read-only or that there are no records in the first place etc. The answers don't make sense.
2) If I bind the form (instead of a table) to a query this way, how do I save this new data into another table? My intention was to have the record saved in Refund table.
Sounds like Refund is your base table here. So, the query you want is:
SELECT a.[ID], b.[Name], c.[Status]
FROM Refund as a
Left Join Retailers as b
ON a.[ID] = b.[ID}
Left Join Registration as c
ON a.[ID] = c.[ID]
You'll need to make all 3 ID fields the Primary Keys in their respective tables. This should make the query updateable, and then you can use this query as the DatSource for your form.
You also have to make sure you set up the Relationships for all the tables. If you've never done it, it's easy to do and Microsoft gives you instructions here:
https://support.office.com/en-us/article/Create-a-relationship-40c998dd-4875-4da4-98c8-8ac8f109b85b
By setting up referential integrity in the relationships, you can save the data.
I am trying to create a table in my database using Visual Studio.
I've got a table for my Products (like in online shop) and then I have a table for Orders, which should store all products that user has ordered. The problem is that I am not sure which datatype I should use when designing the database to store an array of products in my Orders table. This is what the Orders table should look like
You should create Products and Orders table with relationship between them.
Your Orders table should have Id column as well (which is PrimaryKey)
Then you should create Products table, that keeps all the information about products and additionaly OrderId which should be used as Foreign Key to Orders table.
Please look at that link:
https://msdn.microsoft.com/en-us/library/ms189049.aspx
It's also worth of checking:
One To One, One To Many, Many To Many relations in SQLServer to have better understanding and design your data store properly.
In your case you need ProductsOrders table, Many To Many relationship.
In Relational database, you can create a relationship between 2 tables.
The relationship can be
1 to 1 (1 Product - 1 Order)
1 to Many (1 Product - 'n' Order)
Many to Many (n product - 'n' Order)
Based on your scenario, You can choose any of the relationship listed above. While querying from the database, you can easily operate over each order/Product.
I'm using SQL Server as backend and MS Access as a front end, I can create a table in Access with lookup wizard which will allow me to create combo box in the form and select multiple values in the drop down, for example,
Lookup value definition, Drama, adventure, horror etc., in combo box I can select multiple genres for a movie and store them in a single cell on the table.
How to replicate the same with SQL Server as back end, I tried entering multiple value in default value and it won't work. Is this possible with SQL Server?
Entering many values into a single column is a big no no in relational database design.
What you are trying to do here is to realize a many to many relationship. You have multiple items, films or whatever and you have multiple genres.
That is the classical case of a many to many relationship. Usually in such a case you have 3 tables, one representing the items, another representing the genres. In between you've got a third table that has foreign keys to the items and the genres.
In the end you will end up with a table structure like this:
Items ItemToGenre Genres
ID | item ItemID | GenreID ID | genre
And have foreign keys on ItemToGenre.ItemID from Items.ID and on ItemToGenre.GenreID to Genres.ID.
Then you can JOIN your tables to get all genres any specific item has. And do not break atomization.