In our case, it is necessary to form values like these and insert them into the **label** column. Moreover, each sensor should be marked with a unique label like where the symbolic representation corresponds to such values. Each sensor in the table has its own name, location, and type: 1 –analog, 2 –discrete, 3 –valve. We have the **sensors** table for sensors registration. We can use the BEFORE INSERT trigger to perform the actions we need. The generation of such unique values can be automated, but it will be necessary to write code for such purposes. To be sure, such values should not be used in primary keys, but they might be used for some auxiliary identifiers. But what about complex identifier values? For example, depending on the date/time or ). The possibilities of the AUTO_INCREMENT attribute are limited because it can be used only for generating simple integer values. It is quite a convenient solution: Special values auto generation INSERT INTO roomdetails VALUES ('Fitting', NULL) INSERT INTO roomdetails VALUES ('WomanClothing', NULL) INSERT INTO roomdetails VALUES ('ManClothing', NULL) The MyISAM engine has an interesting solution that provides the possibility of generating values for such keys. The rarer case is when the primary key is surrogate - it consists of two columns. **Note: **The next AUTO_INCREMENT value for the table can be parsed from the SHOW CREATE TABLE result or read from the AUTO_INCREMENT field of the INFORMATION_SCHEMA TABLES table. The data selection from the table shows that there are holes in the table in the values of identifiers: Let’s check which LAST_INSERT_ID() values were at different stages of the script execution: INSERT INTO table1 VALUES (NULL), (NULL), (NULL) - 10, 11, 12 INSERT INTO table1 VALUES (NULL) - 9 won't be inserted (hole) INSERT INTO table1 VALUES (NULL) - 8 won't be inserted (hole) INSERT INTO table1 VALUES (NULL) - 7 won't be inserted (hole) Insert operations within rolled back transaction. Insert operations within commited transaction.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |