650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131229/203I52058-0.gif "alt =" y_0040.gif "/> some things are not as much as we thought, but we are scaring ourselves. Especially in programming, it may be that if you ignore a very small problem, you will be entangled for a whole night, and it will be hard for me to go through this line of crying, but the generals are harder than me, so I have to cheer up.
Last night, I got into a trap. I tried to Debug the child paper for one night. It was a dead man!
Project: Create a table using SQL statements and associate several tables.
Question: ① what is reference?
② How to use association in SQL statements?
③ How to use the keyword references? What should I pay attention?
Answer: Reference refers to limiting the data source in the database. The reference exists between two tables. The referenced table is called "parent table", and the referenced table is called "sub table "; if such a reference relationship exists between tables, you must delete the reference fields in the child table before deleting the referenced fields in the parent table.
Illustration: 650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131229/203I513B-1.png "title =" Capture. PNG "alt =" 161102497.png"/>
The value of the "Faculty" field in this table is derived from the "School name" in the following table, which is a reference. That is to say, the reference table does not have a value, and the sub-table cannot appear. This limits the data source of the Word Table.
So how can we use it in SQL statements? It's easy to have a keyword called references, which can be used when writing a query statement.
Why is it still wrong? Pay attention to the following issues:
1. The referenced field or primary key, or the value of the field in the table is unique and contains non-null values)
2. The data type of the referenced field must be highly consistent with that of the referenced field.
3. When designing a database, you must carefully consider which fields will be repeated and which fields will not be repeated.
4. About the primary and Foreign keys. In fact, it is relatively easy. Let's look at the illustration.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131229/203I55216-2.png "title =" Capture. PNG "alt =" 162507343.png"/>
The "Faculty" in the class table (sub-table) references the "School Number" in the school Table (parent table ". At this time, the value of the sub-table column comes from the parent table and is restricted by the parent table. This column of the class table is called the foreign key of the class table, in this case, the primary key is used in the school table.
P.S:Primary Key Selection
A primary key is used to identify a record. We usually select meaningless fields as the primary key. For example, each table usually has an "ID" field, in addition, it is set as the ID column and the auto-increment column is used as the primary key, without any practical significance.
Love jump traps, eager for progress!
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131229/203I52332-3.gif "alt =" j_0047.gif "/> Ajax Girl, come on! 650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131229/203I52332-3.gif "alt =" j_0047.gif "/>
This article is from the "Ajax girl" blog!