How to make a table that could add many same number of different item? I wanted to create a table to store coupons of users.

For example, there is 3 coupon which is A, B and C etc. A user can have 10 coupon A, 20 coupon B and 5 coupon C etc.

How should I create a table to store these? There are many users in the system. How should I create a table which able to store all these information?

If I add another table just for the user and the coupon I still need to add a table which can count the number of the coupon. I have 8 type of coupon. Can I just use a single table and store each coupon for each column and row for the number of coupon?
You can't do it correctly with a single table, more exactly your database will be redundant and seriously vulnerable against inconsistencies.

You should read about database normalization.

A normalized solution would be this:


Table users, columns:


user_id (integer, also primary key)
...any other user data, name etc...

Table coupons, columns:


coupon_id (integer, also primary key)
...any other coupon data, name, value, etc...

Table user_coupon (it is the important), it is a so named bridge table, columns:


user_id (foreign key to users(user_id))
coupon_id (foreign key to coupons(coupon_id))
count (integer, shows how many coupons with id coupon_id has the user user_id)



The important thing is that the primary key on table user_coupon must be user_id and coupon_id!