php - Database Schema suggestions please -
i have scenario , i'm confused how can go designing database schema it.
in software (php) there companies , applications.
companies need have licenses access applications.
now fields (for form while purchasing licenses) each application different.
for ex:
for application1:
fields are:
- no of users
- no of groups
for application2:
- no of users
for application3:
- number of hours of usage
prices based on these fields.
now need design schema on 1 page company can manage licenses applications.
how can make schema generic?
please help. thanks.
you can go type of structure
select * applicationmaster | appid | appname | ------------------------ | 1 | application1 | | 2 | application2 |
applicationmaster go main application related details won't repeated such name, date etc.
query 2:
select * applicationfield | fieldid | appid | fieldname | --------------------------------- | 1 | 1 | noofusers | | 2 | 1 | noofgroups | | 3 | 2 | nohourusage |
applicationfield can adjust number of field particular appid. appid 1 has 2 fields noofusers
, noofgroups
. capable adjust newer fields particular app if want.
query 3:
applicationvalue have values every license aplication have compid represents company has applied using fieldid refers applicationfield
table can app values stored.
select * applicationvalue | id | compid | fieldid | fieldvalue | -------------------------------------- | 1 | 1 | 1 | 50 | | 2 | 1 | 2 | 150 | | 3 | 2 | 3 | 350 | | 4 | 3 | 1 | 450 | | 5 | 3 | 2 | 50 |
applicationpricemaster stores price package each application. there multiple package application.
select * applicationpricemaster | apppackage | appid | totalprice | ----------------------------------- | 1 | 1 | 50 | | 2 | 1 | 100 |
for each application package details posted in table.
select * applicationpricedetail | apppackage | fieldid | quant | -------------------------------- | 1 | 1 | 1 | | 1 | 2 | 1 | | 2 | 1 | 10 | | 2 | 2 | 1 |
note please check structure complex , check type of queries running on these table , performance.
select apm.apppackage, totalprice applicationpricemaster apm inner join (select apppackage applicationpricedetail fieldid=1 , quant=1)a on apm.apppackage = a.apppackage inner join (select apppackage applicationpricedetail fieldid=2 , quant=1)b on a.apppackage=b.apppackage
sql fiddle:
| apppackage | totalprice | --------------------------- | 1 | 50 |
for single filter have use query, have increase number of inner query number of inner filter.
select apm.apppackage, totalprice applicationpricemaster apm inner join (select apppackage applicationpricedetail fieldid=1 , quant=1)a on apm.apppackage = a.apppackage
note-this query quite complex , work if values same mentioned in packagedetail table , work if values 2 filter have remove 1 inner join if there 1 filter. suggest reconsider before using approach.
Comments
Post a Comment