What was the relation in the database?
the relation in question is the relationship between a table with another table of interlocking with one another.
What are the benefits?
Relations benefit is that you can store data from a main data on the other table as an example table member who has a relationship with a hobby table, where there is a hobby of member data stored in the table hobby.
A requirement to make the relations:1. The need to have more than one table.
2. in the second table should have the same field either the name or the data type and size.
3. the master table fields you want in a relationship should be a primary key.
the previous material we already have a database with the name becoding who may have had a friend table that contains the id and the name of a friend, so now we need a single table that stores email data. the following structure:
table name: friend_email
field:
id -> char data type (6)
email -> data type char (35)
query commands manufacture table:
create table friend_email (id char(6) not null,email char(35) not null);
ScreenShot: Create table friend_email [Click Here]
Create relationships
To create a relation is essentially a command:
alter table table_01
add constraint fk_symbol foreign key (field-table_01) references table_02(field);
explanation:
table_01 -> is the table you want to create relationshipstable_02 -> is a master table (table that is a primary key field)
fk_symbol -> foreign key status symbol that is useful for the elimination of the foreign key (fk_symbol free)
field-table_01 -> field on table_01 we want to connect.
field -> field master (the field of the primary key)Then to connect the two tables that we make our command is
alter table friend_email
add constraint fk_email foreign key (id) references friend(id);
ScreenShot: add foreign key [Click Here]
ok relationship has been successfully established.
Remove relations
to remove the command relationship is basically:
alter table table_01
drop foreign key fk_symbol;
explanation:
table_01 -> table that has a foreign key to be removed.fk_symbol -> fk_symbol of the foreign key that we make.then if we want to remove a foreign key that we created earlier then the command is:
alter table friend_email
drop foreign key fk_email;
ScreenShot: Drop foreign key [Click Here]
That's the way to create and delete relationships between tables, explanation hopefully we can be useful to you. Thank you for visiting and reading to the end.motivation today: keep learning to be better :D
Tidak ada komentar:
Posting Komentar