The first paradigm is simple.
Second paradigm:
To put it bluntly, it identifies the objects in the business and defines a database table for each object.
Take the school model as an example. Instructor information table, student information table, class information table .... Each table has an ID as the primary key. Other Fields record the basic information of this object.
1. Instructor table (School_TeacherTab)
If exists (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = 'school _ TeacherTab ')
Drop table School_TeacherTab
Create table dbo. School_TeacherTab (
School_TeacherTabID int identity not null primary key nonclustered,
School_TeacherName VARCHAR (100) not null default''
);
2 student table (School_StudentTab)
If exists (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = 'school _ StudentTab ')
Drop table School_StudentTab
Create table dbo. School_StudentTab (
School_StudentTabID int identity not null primary key nonclustered,
School_StudentName VARCHAR (100) not null default''
);
Third paradigm:
Describes the relationship between a table and a table.
The common relationship between tables is one-to-many (many-to-one, in turn.
For example, a teacher can teach multiple students, and one student can only have one teacher. For example, the martial arts school can accept many disciples, but one person cannot join more than two school sects. In this case, the student table above should be changed:
2 student table (School_StudentTab)
If exists (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = 'school _ StudentTab ')
Drop table School_StudentTab
Create table dbo. School_StudentTab (
School_StudentTabID int identity not null primary key nonclustered,
School_TeacherTabID int not null foreign key references School_TeacherTab (School_TeacherTabID ),
School_StudentName VARCHAR (100) not null default''
);
The preceding table definition indicates different school_studenttabids, which can have the same School_TeacherTabID. This indicates the many-to-one relationship between students and teachers.
Sometimes a table is not only related to another table, but may be related to multiple other tables. Assuming that each disciple is limited to only one weapon, and different disciples may practice the same weapon. Similarly, students have many to one relationships with weapons.
3 weapon table (School_WeaponTab)
If exists (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = 'school _ WeaponTab ')
Drop table School_WeaponTab
Create table dbo. School_WeaponTab (
School_WeaponTabID int identity not null primary key nonclustered,
School_WeaponName VARCHAR (100) not null default''
);
The student table is in the following format:
2 student table (School_StudentTab)
If exists (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = 'school _ StudentTab ')
Drop table School_StudentTab
Create table dbo. School_StudentTab (
School_StudentTabID int identity not null primary key nonclustered,
School_TeacherTabID int not null foreign key references School_TeacherTab (School_TeacherTabID ),
School_WeaponTabID int not null foreign key references School_WeaponTab (School_WeaponTabID ),
School_StudentName VARCHAR (100) not null default''
);
The second paradigm requires us to identify the disciples, teachers, and weapons and define them into tables. If the above student table contains the weapon table id, the weapon name is also saved, which violates the second paradigm.
Many-to-many relationship:
Assume that the relationship between students and teachers is many-to-many. For example, Guo Jing regards Ke Zhen as a teacher and Hong qigong as a teacher. In addition to Guo Jing, Hong Qigong also accepts Huang Rong as a disciple.
In this case, you cannot add a foreign key to the teacher's table or the foreign key to the student's table. Instead, we need to create a new instructor-student relationship table, which is different from the above object table (Describing object information). It describes the relationship between objects.
4 instructor _ student table (School_TeacherStudentTab)
If exists (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = 'school _ TeacherStudentTab ')
Drop table School_TeacherStudentTab
Create table dbo. School_TeacherStudentTab (
School_TeacherStudentTabID int identity not null primary key nonclustered,
School_TeacherTabID int not null foreign key references School_TeacherTab (School_TeacherTabID ),
School_StudentTabID int not null foreign key references School_StudentTab (School_StudentTabID ),
);