← Back to PostgreSQL Course | Chapter 1: Introduction | Lesson 2 of 7

SQL बनाम NoSQL

PostgreSQL जैसे Relational databases fixed tables और SQL इस्तेमाल करते हैं, जबकि NoSQL databases structure की जगह flexibility लेते हैं।

In this page:

  1. SQL बनाम NoSQL

SQL बनाम NoSQL

एक relational database एक defined schema वाली tables में data store करता है, keys से relationships enforce करता है, और SQL और joins इस्तेमाल करता है।

NoSQL systems (document, key-value, graph, column) flexible schemas चुनते हैं और अक्सर horizontally scale होते हैं। PostgreSQL JSONB से इस line को धुंधला करता है, इसलिए आप structured columns और flexible documents mix कर सकते हैं।

Note: जब data में clear relationships हों और आपको transactions चाहिए एक relational database इस्तेमाल करें।

उदाहरण: SQL vs NoSQL

sql
CREATE TABLE customers (id INTEGER PRIMARY KEY, name TEXT, city TEXT);
CREATE TABLE orders (id INTEGER PRIMARY KEY, customer_id INTEGER, total INTEGER);
INSERT INTO customers VALUES (1, 'Ada', 'London'), (2, 'Bob', 'Oslo');
INSERT INTO orders VALUES (10, 1, 50), (11, 1, 20), (12, 2, 75);
-- Relational: related data lives in separate tables and is combined with a JOIN
SELECT c.name, o.total FROM customers c JOIN orders o ON o.customer_id = c.id ORDER BY o.id;

-- Output:
-- name | total
-- Ada | 50
-- Ada | 20
-- Bob | 75
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. सिर्फ trendy होने की वजह से NoSQL चुनना
  2. एक relational database में सब कुछ JSON की तरह store करना
  3. यह मान लेना कि SQL scale नहीं कर सकता
चैप्टर सारांश
  • SQL databases tables, schemas, और joins इस्तेमाल करते हैं
  • NoSQL structure की जगह flexibility लेता है
  • PostgreSQL JSONB भी support करता है
  • Data shape और consistency needs से चुनें
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.