Degree in SQL refers to the number of attributes or columns in a table, while cardinality defines the number of rows or tuples. In this blog, we will learn about degree and cardinality in SQL.
Table of contents
What is Degree in SQL?
In SQL, Degree stands for the number of columns that are present in a table. A table with N number of columns can be said to have a degree of N.
Example of Degree in SQL
CREATE TABLE IntellipaatStudent( StudentID INT, Name VARCHAR(50), Age INT );
The table Students has 3 Columns StudentID, Name, and Age. so it can be said that the table is of degree 3.
What is Cardinality in SQL?
In SQL, the cardinality is defined as the number of rows(tuples) present in the table. Cardinality can be classified into two types: the relationship between tables and data in a column.
Example of Cardinality in SQL
If a table contains 50 records of students, then the cardinality of the student table is 50, because it has 50 rows.
Types of Cardinality in SQL
Types of cardinality based on the relationship between tables:
- One-to-One (1:1): In this relationship, one entity of table A is linked with exactly one entity of table B.
- One-to-Many (1:N): In this relationship, one entity of table A may be linked with more than one entity of table B.
- Many-to-One (N:1): In this relationship, more than one entity of table A may be linked to exactly one entity of table B.
- Many-to-Many (M: N): In this relationship, more than one entity of table A may be linked with more than one entity of table B.
If you are a beginner and want to learn about SQL in detail from scratch, please refer to our YouTube video:
Conclusion
In conclusion, The degree and cardinality of SQL both define and describe the size and structure of the relational tables. The degree is the number of columns present in a table, while cardinality is the number of rows present in the table.
If you want to learn more about SQL, please refer to our SQL course to enhance your knowledge about SQL.