Table
Create a Database
CREATE DATABASE example_db;
Drop the Database
DROP DATABASE example_db;
Create a Table
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(150) UNIQUE NOT NULL,
age INT CHECK (age >= 0),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Insert Data into the Table
INSERT INTO users (name, age, email)
VALUES
('Alice', 25, 'alice@example.com'),
('Bob', 30, 'bob@example.com');
INSERT INTO users VALUES
('Alice', 'alice@example.com', 25),
('Bob', 'bob@example.com', 30);
Query the Data
SELECT * FROM users;
SELECT name FROM users;
Update Data
UPDATE users
SET age = 26
WHERE name = 'Alice';
Delete Data
DELETE FROM users
WHERE name = 'Bob';
Drop the Table
DROP TABLE users;