
Make sure to follow our blog for the latest updates. Later we will talk more about various data types and constraints in a table. To insert text in a column we can use char(n) for fixed length string and varchar(n) for variable length string where n is the length of the string. And the pay_date is a date (year, month, day) type. The employee_id and amount is of int type, sort for integer. the first row gets the value of 1, second row 2, and so on. It is a special integer data type that auto-increments every time you add a new row to the table. The id column in this table is bigserial data type. To create a table in a database we use the CREATE TABLE statement followed by the table name. If you enter a text data into a date column then you will get an error. The Data type of a column determine what kind of data can be stored in that column. When you create a table, you assign a name to each column (sometimes referred to as a field or attribute) and assign it a data type. Each rows holds a collection of columns, and each column contains data of a specified type: most commonly, numbers, characters, and dates.

In the object browser right click on lwd and select Query Tool.Close the query tool by click x on top right, no need to save the previous query.Now that we have successfully created the lwd database but before we create any table we have to make sure that we are connected to this database and not the default postgres database. Once you execute the query, right click and refresh the Databases on the left navigation, you will see that lwd database is created. This statement creates a database on your server named lwd using default postgres settings. Open the pgAdmin > PostgreSQL 14 > Databases > postgres > right click on postgres > Query Tool You can find the instruction for installing PostgreSQL and pgAdmin from here – Open the pgAdmin tool that we installed previously.

To create a database in SQL, we use the CREATE DATABASE statement. Let’s create a database Life with data (lwd) to store both employee and salary table. Together, the data and the DBMS, along with the applications that are associated with them, are referred to as a database system, often shortened to just database. A database is usually controlled by a database management system (DBMS). And employee_id in the Salary table is a foreign key for the employee table.Ĭreating a Database in PostgreSQL – What is a database ?Ī database is an organized collection of structured information, or data, typically stored electronically in a computer system. Id is the primary key for the Salary table and employee_id is the primary key for the employees table. Th employees salary information are in the Salary table and employees information in employees table.

Let’s say you have some data about your company and want to create a database and tables to store and analyse this data.
