How to create table in SQL/Postgresql database?

DATA DEFINITION LANGUAGE

Table creation in SQL is a Data Definition Language (DDL) command. The database’s structure is related to DDL commands. How the tables will be created, modified, and deleted.

POSTGRESQL DATABASE TABLE

Data is stored in tables in the form of rows, often referred to as records, in relational databases. There are rows and columns in a table. Additional characteristics of a database table include things like the Data Type, Column Name, Column Number (#), etc.

TABLE CREATION SYNTAX AND EXAMPLE

-- Syntax 
CREATE TABLE table_name (
	  column1 data_type,
	  column2 data_type
	);

-- Example 1
CREATE TABLE products (
	product_no integer,
	product_name text,
	price numeric
	);
CREATED TABLE DETAILS

TABLE CREATION WITH DEFAULT VALUES

In Postgresql database , you can also specify default values for a column when establishing a table, meaning that if a user doesn’t supply any values for that column, a default value will be assigned automatically.

-- Example 2
CREATE TABLE products (
	product_no integer,
	product_name text,
	price numeric default 9.99
	);

TABLE CREATION FROM EXISTING TABLE

Sometimes you may need to create a table that is identical to one that already exists but has a different purpose. You may require it for testing purposes or just for a backup before carrying out important activities on it. You may easily make such a table.

-- EXAMPLE 3
CREATE TABLE students_temp as 
select * from students;
students_temp table creation from existing table.
students_temp table records same as students table.