Database Essentials using Postgres - Creating Table in Postgres Database

Description:
This article serves as a beginner’s guide to learning SQL basics through hands-on exercises. It includes step-by-step instructions, key concept explanations with code examples, and practical tasks for readers to apply the concepts discussed in the article.

Explanation for the video:

[PLACEHOLDER FOR THE VIDEO]

Key Concepts Explanation

Creating Table

Before delving into basic DML and queries (CRUD operations), tables need to be created. All database operations related to managing tables fall under DDL.

To create a table, connect to the database and run the following CREATE TABLE statement.

DROP TABLE IF EXISTS users;

CREATE TABLE users (
    user_id SERIAL PRIMARY KEY,
    user_first_name VARCHAR(30) NOT NULL,
    user_last_name VARCHAR(30) NOT NULL,
    user_email_id VARCHAR(50) NOT NULL,
    user_email_validated BOOLEAN DEFAULT FALSE,
    user_password VARCHAR(200),
    user_role VARCHAR(1) NOT NULL DEFAULT 'U',
    is_active BOOLEAN DEFAULT FALSE,
    create_ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    last_updated_ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

To validate the created objects in the database, run the following queries against the information_schema or use tools like SQL Workbench.

SELECT * FROM information_schema.tables 
WHERE table_catalog = 'itversity_sms_db' AND table_schema = 'public'
LIMIT 10;

SELECT * FROM information_schema.columns 
WHERE table_name = 'users'
LIMIT 10;

Key Concept 1

Description of the key concept 1 with inline code examples
Multi line code examples (if any) should be highlighted using code highlighter

Key Concept 2

Description of the key concept 2 with inline code examples
Multi line code examples (if any) should be highlighted using code highlighter

Hands-On Tasks

Description of the hands-on tasks. Provide a list of tasks that the reader can perform to apply the concepts discussed in the article.

  1. Task 1
  2. Task 2

Conclusion

Summary of the main points discussed in the article. Encourage the reader to practice or engage with the community for further learning.

Invitation to Join the Community: Gently remind readers to sign up or log in if they wish to participate in discussions or ask questions.

Remove timestamps and any references to the medium articles.

Watch the video tutorial here