Domanda

I'm struggling, hope you can help me out! The application is an ERP system in MS ACCESS for fashion retailing.

The question: How can I add a row in Table3 with the article's corresponding SizeID1, SizeID2 etc filled according to it's size system of Table2?

Table1: Article details containing size system

ArticleID | SizeType
--------------------  
1         | US  
2         | EU  

Table2: Different size systems for different regions

SizeID | Size | SizeType 
------------------------ 
1      | S    | US
2      | M    | US
3      | L    | US
4      | XL   | US
5      | 36   | EU
6      | 38   | EU
7      | 40   | EU

Table3: Order details

OrderID | ArticleID | Size1 | Amount1 | Size2 | Amount2 | Size3 | Amount3  
------------------------------------------------------------------------- 
1       | 1         | S     | 1       | M     | 3       | L     | 1  
2       | 2         | 36    | 2       | 38    | 1       | 40    | 3
3       | 2         | 36    |         | 38    |         | 40    |

The row with OrderID = 3 is the goal of the insery query for ArticleID 2. I can then enter the amount to the corresponding size. Thanks for your help!!

È stato utile?

Soluzione

It's not entirely clear what you're trying to achieve here, but I think that might be because your database design is a bit broken.

You're probably used to working with spreadsheets, becase you seem to have designed your Table3 as if it were a spreadsheet. Any time you end up with repeating fields in a database table (eg. Size1, Size2, Size3....) then it's a sign that you need to normalise more.

Please read up on database normalisation: http://www.studytonight.com/dbms/database-normalization.php (and also google generally for database normalisation for more info).

I suspect you'll need something more like this:

Article table:

ArticleID | ArticleName   | SizeType(FK to SizeType table)
1         | Blue T-shirt  | 1
2         | Red T-shirt   | 2

SizeType table:

SizeTypeID | SizeTypeDescription
1          | US
2          | EU

Sizes table:

SizeID | SizeType(FK) | SizeDescription
1      | 1            | 38
2      | 1            | 40
3      | 2            | M
4      | 2            | L

Items table:

ItemID | ArticleID(FK) | SizeID(FK)
1      | 1             | 1      'Blue T-shirt size 38
2      | 1             | 2      'Blue T-shirt size 40
3      | 2             | 3      'Red T-shirt size M
4      | 2             | 4      'Red T-shirt size L

Orders table:

OrderID | CustomerID (FK) | OrderDate | etc. (other info you need to store about an order)
1       | 2458            | 01/01/2001|
2       | 3452            | 02/02/2002|

Order Details table:

OrderDetailsID | OrderID(FK) | ItemID (FK) | Quantity
1              | 1           | 3           | 6
2              | 1           | 4           | 3
3              | 2           | 1           | 1

So here linking everything back, Customer with ID 2458 has ordered 6x Size M Red T-shirts and 3x Size L Red T-shirts, and Customer with ID 3452 has ordered 1x size 38 Blue T-shirt.

Note You'd also realistically have a PRICE field in either the Items table (if the price varies with the size of an item) or in the Article table (if the price is the same for every size). CustomerID would also link back to a table containing a customer's details (Name, address, username/password etc).

You might also have other things that I've not shown here, for example in either your Articles table or your Items table you'll probably have a supplierID which tells you who you buy that item from, as well as a supplierItemNo which would be a unique code (barcode?) which you use to order that item.

Once your database is structured properly it will be much easier to write queries to insert records etc.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top