Open In App

Components of Table in Database

Last Updated : 09 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

In the changing world of a database, tables are the fundamental structures that organize and save data with precision. A table, in the context of a database, is a scientific arrangement of records offered in rows and columns. It improves the performance of information control and retrieval. In this article, we will go through the essential components of the table in the database. We will also examine the significance of the column names, data types, and key identifiers, including primary and foreign keys.

What is a Table in a Database?

A table is a collection of related data in an organized manner in the form of rows and columns. It is an organized arrangement of data and information in tabular form containing rows and columns, making it easier to understand and compare data.

Here is the pictorial representation of the table and its different components containing the data about different students that is ID, name, Age, and course.

Table

Structure of Table

Now let’s create the above table in SQL server management studio.

Create a Database using the below query.

CREATE DATABASE StudentsDatabase;

Create a Table named as Students.

CREATE TABLE Students (
ID INT PRIMARY KEY,
NAME VARCHAR(50),
AGE INT,
COURSE VARCHAR(50)
);

Insert the data into it.

INSERT INTO Students (ID, NAME, AGE, COURSE)
VALUES
(1, 'MINAL', 22, 'COMPUTER SCIENCE'),
(2, 'MRIDUL', 21, 'CIVIL'),
(3, 'MARAM', 19, 'CHEMICAL'),
(4, 'MOHAMMAD', 24, 'ELECTRICAL');

Now let’s verify whether the data is inserted or not.

SELECT * FROM Students;

Output:

You can see the table was created successfully.

StudentsTable

Students Table

Elements of a Table

1. Columns

Also known as fields or attributes. Each type of information present in the vertical position is known as columns or fields. They allow us to sort and filter data in a table. In the above-given example, ID, Name, Age, and Course are different columns.

column

Column

2. Row

Also known as a tuple or record. The data of each student in a horizontal position is known as row or record. Each record holds the total data for a specific student. First row represents that the student of ID 1 has the name Minal, age 22 and course in Computer Science.

row

Row

3. Column Name

Each column or Field has its unique name. The first column name is ID which stores the ID of each student, second column name is NAME which holds the name of each student for every tuple and so on.

4. Data Items

Column values are the information stored in a specific cell within a column for a particular row. Every point where a row and a column cross signifies a distinct piece of data. Every cell in Students table has a data item that represents a particular student attribute, such as ID, NAME, AGE, or COURSE.

DataItems

Column Values

5. Data Types

Each column in a table is associated with a specific data type that defines the kind of data it can store. Some of the data types are int, varchar, char, date, etc. Data types ensures that the data entered in the column belongs to a particular format and structure to the stored information. For example ID and age might be integer, and Name and course could be strings.

6. Primary Key

It is the unique identifier for each row in a table. There can only be one primary key in a table, and it can’t be null. ID is the primary key for the above table. Each student is uniquely identified by their ID. Now two rows have the same ID. The first column is usually the primary key of the table.

primary

Primary Key

7. Foreign Key

A foreign key is a column or a set of columns in a table that refers to the primary key of another table. It establishes the relationship between the table. A foreign key can be null and there can be more than one foreign key in the table. For example, in the Department table you might have an emp_id column as a foreign key. This allows you to link departments to specific employees.

foreignKey

Foreign Key

Conclusion

In Conclusion, the table is a fundamental component of relational database design, making a well-structured and logical framework for the storing and retrieval of data. Databases are made into effective tools by carefully organizing columns and rows to convert unprocessed data into valuable information. Each dataset’s content is represented by the column names and data items, providing accessibility and clarity.

By considering the columns, data types,column names, rows, primary keys, data items, and foreign keys, database designers can create well-defined and organized structures that support data integrity and effective data manipulation.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads