In addition to this contraint/rule the ON DELETE CASCADE (there are other options but CASCADE option is perhaps the most useful) says that should the parent (user_table row or contacts_table row respectively) be deleted then the deletion will be cascaded to the children and thus that the rows in the user_contact_map will be deleted. This, for example, says that the value of the userId_map column MUST be value that exists in the userId column of the user_table otherwise an error is raised. UserId_map INTEGER REFERENCES user_table(userId) ON DELETE CASCADE ON UPDATE CASCADE,ĬontactId_map INTEGER REFERENCES contacts_table(contactId) ON DELETE CASCADE ON UPDATE CASCADE, ![]() So instead you could, for example, have :- CREATE TABLE IF NOT EXISTS user_contact_map ( being incorrect so you can introduce rules that enforce the integrity of the references (referential integrity) by the use of Foreign Key constraints. However, this is prone to references/mappings. So you could for example have CREATE TABLE IF NOT EXISTS user_contact_map (userId_map INTEGER, contactId_map INTEGER, PRIMARY KEY(userId_map, contactId_map)) It would appear that userId and contactId probably have this attribute. The map/reference being something that uniquely identifies the user and also the contact. Such a table has two columns (or more) one of which holds a reference/map to the user and the other a reference/map to the contact. Such a table has many names such as an associative table, a mapping table, a reference table. Thus a user can have many contacts and a contact can have many users. This involves using a 3rd table that maps a user to a contract and also a contact to a user. In this case a many-many relationship can be used. ![]() ![]() You say that "user enter as many contacts as it wants to" and then say "so different user can see the same contacts".
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |