Creating Tables

Learn about data types, primary key, and table creation in relational database.

Relational database

When a table is organized in a manner where each row can be distinctly identified, and every cell in the table contains a single, indivisible value, the table is termed a relation. A collection of such tables forms a relational database

Data types

Each column in a table is associated with a specific data type, which defines the kind of data that can be stored in that column. It helps the database system understand how to store, retrieve, and manipulate the data. Here’s a brief overview of some common data types:

  • INTEGER or INT: The INT data type is employed to represent whole numbers without decimal points. For example, EmployeeID INT.

  • DECIMAL or DEC: The DECIMAL data type is utilized for storing decimal numbers and is defined as DECIMAL(p, s), where p denotes the total number of digits and s indicates the number of digits reserved for the decimal part. For instance, in DECIMAL(10, 2), 10 digits are allocated in total, with 2 specifically reserved for the decimal part. For example: Price DECIMAL(8, 2).

  • CHAR: The CHAR data type is used to store fixed-length character strings. It is defined as CHAR(size), where size represents the number of characters for that field. For example: DepartmentName CHAR(20).

  • DATE: The DATE data type is used to represent dates. For example: ExamDate DATE.

Primary key

In a relational database, it is imperative that every table has a designated primary key, which can be a single column or a combination of columns. This primary key serves as a unique identifier for each row.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy