Q1. What is the difference between OLTP and OLAP databases?
basicAnswer
OLTP (Online Transaction Processing): Optimized for writes, normalized data, row-oriented, used for daily operations. OLAP (Online Analytical Processing): Optimized for reads, denormalized/star schema, column-oriented, used for analytics and reporting.
Example Code
1-- OLTP: Normalized tables, frequent small transactions
2CREATE TABLE orders (id SERIAL PRIMARY KEY, customer_id INT, total DECIMAL);
3CREATE TABLE order_items (order_id INT, product_id INT, quantity INT);
4
5-- OLAP: Denormalized fact table with dimensions
6CREATE TABLE fact_sales (
7 date_key INT,
8 product_key INT,
9 customer_key INT,
10 quantity INT,
11 revenue DECIMAL
12);