Basic Maintenance of the examination system-connection to the basic table

Source: Internet
Author: User
This time, I was lucky enough to help my sister with basic maintenance of the examination system. The direct point was to manage the examination staff, add, delete, modify, and query. The most important thing was to query the students and check the information given by the teacher, finally, confirm the examination personnel. During the query process, they encountered such a situation: when checking the English examination personnel, in order to facilitate the query

This time, I was lucky enough to help my sister with basic maintenance of the examination system. The direct point was to manage the examination staff, add, delete, modify, and query. The most important thing was to query the students and check the information given by the teacher, finally, confirm the examination personnel. During the query process, they encountered such a situation: when checking the English examination personnel, in order to facilitate the query

This time, I was lucky enough to help my sister with basic maintenance of the examination system. The direct point was to manage the examination staff, add, delete, modify, and query. The most important thing was to query the students and check the information given by the teacher, finally, confirm the examination personnel. During the query process, they encountered such a situation:

When checking the English examination personnel, a related view is created to facilitate the query. The tables involved in this view include TB_Student (basic student information ), TB_ExecutiveClass (the class involved), TB_DepartmentName (Major), TB_CollegeName (school ), TB_English mainly refers to the establishment of an overall information table based on the basic information of students and the information related to the college and English exams. The first part of information check is to check whether the information in the view is exactly the same as the English information table given by the teacher.

After busy for half a day, I finally made a right outer connection to the table according to the idea of my sister-in-law. I checked the table based on the student's English classification information:

The related statements are as follows:

SELECT DISTINCT
Dbo. TB_Student.StudentName, dbo. TB_Student.StudentCode, dbo. TB_Student.Sex, dbo. example, dbo. TB_Department.DepartmentName,
Dbo. TB_College.CollegeName, dbo. TB_Grade.GradeName, dbo. tb_engish.engisfenji, dbo. tb_engish.engishclass
FROM dbo. TBR_DepCollegeLink INNER JOIN
Dbo. TB_Department ON dbo. tbr_depcollegelink.mongomentid = dbo. tb_department.mongomentid INNER JOIN
Dbo. TB_College ON dbo. TBR_DepCollegeLink.CollegeID = dbo. TB_College.CollegeID INNER JOIN
Dbo. TBR_ExecutiveClassDepLink ON dbo. TB_Department.DepartmentID = dbo. TBR_ExecutiveClassDepLink.DepartmentID INNER JOIN
Dbo. TBR_StuExecutiveClassLink INNER JOIN
Dbo. TB_ExecutiveClass ON dbo. TBR_StuExecutiveClassLink.ExecutiveClassID = dbo. TB_ExecutiveClass.ExecutiveClassID INNER JOIN
Dbo. TB_Student ON dbo. TBR_StuExecutiveClassLink.StudentID = dbo. TB_Student.StudentID ON
Dbo. TBR_ExecutiveClassDepLink.ExecutiveClassID = dbo. TB_ExecutiveClass.ExecutiveClassID INNER JOIN
Dbo. TBR_ExecutiveClassGradeLink ON dbo. TB_ExecutiveClass.ExecutiveClassID = dbo. TBR_ExecutiveClassGradeLink.ExecutiveClassID INNER JOIN
Dbo. TB_Grade ON dbo. TBR_ExecutiveClassGradeLink.GradeID = dbo. TB_Grade.GradeID RIGHT OUTER JOIN
Dbo. TB_english ON dbo. TB_Student.StudentCode = dbo. TB_english.studentCode

The result is as follows:

Why is this happening? The reason is, of course, very simple. Because the data in the T_English table is directly imported into the Excel table given by the teacher, the equivalent amount of data will appear if external connections are used, however, for some reason, when I first added the basic information, I forgot the student, or I only deleted the student after I switched to a major, but I forgot to add it to the basic student table, and so on. As a result, the basic student table is empty, this is why.

A simple query is performed through the connection operation of the basic table, and then a comparison is performed to find that these five data entries are real. Ah! This time it really helped me a lot.

In fact, the right outer join is only a connection type in the basic table. In addition, the connection type of the data table is divided:

1) Internal Connection: equivalent connection

2) Outer Join: Check whether Table A or table B is the primary information. If table A is used as the basis, use the left Outer Join. Otherwise, use the right outer join. Full outer join is not restricted for both tables.

3) Natural join: The join occurs in a table.

The following is an example to describe in detail:

Table TB_student and table TB_English

For natural connections, it is generally used in the case of public attributes. If the two links do not have public attributes, the natural connections are converted to the Cartesian Product for operation.

Decathlon product:
SELECT     dbo.TB_English.studentCode, dbo.TB_English.englisfenji, dbo.TB_Student.StudentCodes, dbo.TB_Student.StudentNameFROM         dbo.TB_English CROSS JOIN                      dbo.TB_Student
Display Effect:

Internal Connection:
SELECT     dbo.TB_English.studentCode, dbo.TB_English.englisfenji, dbo.TB_Student.StudentCodes, dbo.TB_Student.StudentNameFROM         dbo.TB_English INNER JOIN                      dbo.TB_Student ON dbo.TB_English.studentCode = dbo.TB_Student.StudentCodes

Left Outer Join:
SELECT     dbo.TB_English.studentCode, dbo.TB_English.englisfenji, dbo.TB_Student.StudentCodes, dbo.TB_Student.StudentNameFROM         dbo.TB_English LEFT OUTER JOIN                      dbo.TB_Student ON dbo.TB_English.studentCode = dbo.TB_Student.StudentCodes

Outer right connection:
SELECT     dbo.TB_English.studentCode, dbo.TB_English.englisfenji, dbo.TB_Student.StudentCodes, dbo.TB_Student.StudentNameFROM         dbo.TB_English RIGHT OUTER JOIN                      dbo.TB_Student ON dbo.TB_English.studentCode = dbo.TB_Student.StudentCodes

All external connections:
SELECT     dbo.TB_English.studentCode, dbo.TB_English.englisfenji, dbo.TB_Student.StudentCodes, dbo.TB_Student.StudentNameFROM         dbo.TB_English FULL OUTER JOIN                      dbo.TB_Student ON dbo.TB_English.studentCode = dbo.TB_Student.StudentCodes

Summary:

This operation on basic information has made you familiar with SQL queries and so on. It is true that you are familiar with practical knowledge! Although it is only a small knowledge point, this basic information maintenance helps you better understand these basic learning needs to be solid! This knowledge seems simple, but if you do not know it, it will actually greatly reduce your query efficiency!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.