Creating Tables
Learn about data types, primary key, and table creation in relational database.
We'll cover the following
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
orINT
: TheINT
data type is employed to represent whole numbers without decimal points. For example,EmployeeID INT
.DECIMAL
orDEC
: TheDECIMAL
data type is utilized for storing decimal numbers and is defined asDECIMAL(p, s)
, wherep
denotes the total number of digits ands
indicates the number of digits reserved for the decimal part. For instance, inDECIMAL(10, 2)
, 10 digits are allocated in total, with 2 specifically reserved for the decimal part. For example:Price DECIMAL(8, 2)
.CHAR
: TheCHAR
data type is used to store fixed-length character strings. It is defined asCHAR(size)
, wheresize
represents the number of characters for that field. For example:DepartmentName CHAR(20)
.DATE
: TheDATE
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