Demand:
Ability to dynamically display forms based on the database, including form types, names, etc., and must provide features such as adding new forms, modifying forms, and so on.
In order to meet the changing needs of customers, sometimes need to add, modify, delete, attribute for a product, so that the previous database table is difficult to achieve,
Because the table field is dead. If you need to add a property, you must modify the table, I heard that this is not allowed ~ ~.
So we're going to design a flexible database. Take a computer device as an example:
PC existing properties name CPU RAM Disk now we want to add a Mainboard property to the PC.
Now that we have to provide an add-on form, we cannot create the table with CPU RAM disk as the column name of the PC table, can be modified can only be value
So you should create a property sheet to hold these values
CREATE TABLE Y_property (
Proid VARCHAR2 (+) primary key,
Proname varchar2 (,--) property name
Htmltype varchar2 (,--) interface type
Isneed number--is required
)
Proid |
Proname |
Htmltype |
Isneed |
P001 |
Model |
Text |
0 |
P002 |
Cpu |
Text |
0 |
P003 |
Ram |
Select |
0 |
p004 |
Disk |
Select |
0 |
Then you create a table to hold the values for these computer properties
CREATE TABLE Y_provalues (
Proid VARCHAR2 (32),--Attribute ID
Entity VARCHAR2 (32),--Instance ID
Provalue varchar2 (1024x768),--attribute value
Constraints pro_fk_proid foreign KEY (proid) references Y_property (proid),
Constraints PROVALUES_PK primary KEY (proid,entity)
)
Proid |
Entity |
Provalue |
P001 |
e001 |
Lenovo Yang Tian V45 |
P002 |
e001 |
AMD5200 |
P003 |
e001 |
Kingston |
p004 |
e001 |
wd500g |
P001 |
e002 |
HP450 |
P002 |
e002 |
INTEL458 |
P003 |
e002 |
Black King |
p004 |
e002 |
wd320g |
In fact, it can also be understood as:
Y_property This table is a class
Y_provalues This table is an example of the Y_property class. The Entity property is the instance number, which is a product number that actually exists.
In addition, we can expand other tables on this basis to make them more versatile,
such as computer grade table, CPU table (so we can y_provalues in the Provalue and other tables, in the interface can provide drop-down list display, select)
This way, you can add attributes to a computer product.
The next task is to make a dynamic form of an engineering implementation interface.
Dynamic form Database Design