mysql the main table and the table

Said example, such as bank account numbers and user tables table, there is no user, then to the bank account, and the user may not have bank accounts, mainly here in this table must have fields for the user in the user table in the bank account, this main table for the user table, from the table, the main table attached.


 

Primary table
created in the database tables i.e. Table, where there is a primary key unique identification (primary key) for the associated other tables and, as in the primary table.
From the table
to the master table's primary key (primary key) table is a foreign key (Foreign Key), the query may be associated with the key through the outer primary table. From the table associated with the master table through the outer query key.
Relations Overview and usage
data from the table depends on the main table, the main table and associate general query from the table when the last query data. The main master table can be used to store information, such as customer information (customer number, customer name, customer company, customer units), from table to store customer information extensions (customer order information, customer address information, customer contact information, etc.)

 

Simple example:

Primary table (user information) 
Table User 
the userid numeric (0,20) 
username VARCHAR2 (20 is) 
usercompany VARCHAR2 (50)

  

Table (customer orders) 
Table uorder 
OrderID numeric (0,20) 
UID numeric (0,20) 
ordertime DATE 
OrderState char (. 1)

  

To the main table and the table of information from a union query statement simply as follows:

select * from user u inner join uorder o on u.userid=o.uid

  


It is a simple-to-many relationship
One of the main table
are mostly from the table

Guess you like

Origin www.cnblogs.com/xinruyi/p/11279627.html