diff --git a/README.md b/README.md index 5befbc18e..a01737913 100644 --- a/README.md +++ b/README.md @@ -333,19 +333,19 @@ Thanks to these amazing people who have contributed to the **Algo** project: - - PrAyAg9 + + Shariq2003
- Prayag Thakur + Shariq
- - AE-Hertz + + MithanshuHedau
- Abhinandan + Mithanshu Hedau
@@ -356,17 +356,24 @@ Thanks to these amazing people who have contributed to the **Algo** project: - - MithanshuHedau + + AE-Hertz
- Mithanshu Hedau + Abhinandan
- - Shariq2003 + + PrAyAg9
- Shariq + Prayag Thakur +
+ + + + shriyadindi +
+ Shriya Dindi
@@ -376,6 +383,8 @@ Thanks to these amazing people who have contributed to the **Algo** project: Mugundh J B + + pratheekv39 @@ -383,8 +392,6 @@ Thanks to these amazing people who have contributed to the **Algo** project: V Pratheek - - monishkumardvs @@ -392,13 +399,6 @@ Thanks to these amazing people who have contributed to the **Algo** project: Dvs monish kumar - - - shriyadindi -
- Shriya Dindi -
- aditiverma-21 @@ -407,40 +407,54 @@ Thanks to these amazing people who have contributed to the **Algo** project: - - Alpha1zln + + Subashree-selvaraj
- SHREYAS YADUVANSHI + subashree
- - Rashigera + + Abhishek2634
- Rashigera + Abhishek Farshwal
- - Subashree-selvaraj + + KashishJuneja101003
- subashree + Kashish Juneja
- - Abhishek2634 + + jainaryan04
- Abhishek Farshwal + Aryan Ramesh Jain
- - KashishJuneja101003 + + Alpha1zln
- Kashish Juneja + SHREYAS YADUVANSHI +
+ + + + Rashigera +
+ Rashigera +
+ + + + Riddhi12349 +
+ riddhi
@@ -457,6 +471,8 @@ Thanks to these amazing people who have contributed to the **Algo** project: Tatheer Fathima + + Mansi07sharma @@ -465,14 +481,12 @@ Thanks to these amazing people who have contributed to the **Algo** project: - - Riddhi12349 + + mehul-m-prajapati
- riddhi + Mehul Prajapati
- - tanishqkolhatkar93 @@ -487,13 +501,6 @@ Thanks to these amazing people who have contributed to the **Algo** project: PavanTeja2005 - - - mehul-m-prajapati -
- Mehul Prajapati -
- sarthaxtic @@ -502,27 +509,20 @@ Thanks to these amazing people who have contributed to the **Algo** project: - - jainaryan04 + + shimmer12
- Aryan Ramesh Jain + Srishti Soni
+ + Asmi1108
Asmi
- - - - - - shimmer12 -
- Srishti Soni -
diff --git a/docs/languages/SQL/sql-25.md b/docs/languages/SQL/sql-25.md new file mode 100644 index 000000000..9b252f4d3 --- /dev/null +++ b/docs/languages/SQL/sql-25.md @@ -0,0 +1,87 @@ +--- +id: sql-json-data +sidebar_position: 25 +title: "JSON Data in SQL" +sidebar_label: "JSON Data in SQL" +description: "Handling JSON Data Within SQL." +tags: [sql, dbms, database, json, data, backend] +--- + +## Introduction +With the growing use of JSON (JavaScript Object Notation) for data exchange, many modern databases have introduced native support for JSON data types. This enables efficient querying and manipulation of JSON data directly within SQL. + +## JSON Data Type +Many SQL databases, including MySQL, PostgreSQL, and SQL Server, support a `JSON` data type, allowing structured data to be stored in a single column. + +### Benefits: +- **Structured Storage**: Store hierarchical data. +- **Efficient Access**: Query and manipulate JSON data using SQL. +- **Flexibility**: Schema-less data storage. + +## Storing JSON in SQL +You can store JSON data in a `JSON` or `TEXT` column depending on the database. + +### Example: +```sql +CREATE TABLE users ( + id INT PRIMARY KEY, + details JSON +); + +INSERT INTO users (id, details) VALUES +(1, '{"name": "Alice", "age": 30, "email": "alice@example.com"}'); +``` + +## Querying JSON Data +SQL provides functions to query and extract values from JSON data. + +### MySQL: +```sql +SELECT details->'$.name' AS name FROM users; +``` + +### PostgreSQL: +```sql +SELECT details->>'name' AS name FROM users; +``` + +### SQL Server: +```sql +SELECT JSON_VALUE(details, '$.name') AS name FROM users; +``` + +## Modifying JSON Data +Use JSON functions to update, add, or remove JSON elements. + +### MySQL Example: +```sql +UPDATE users SET details = JSON_SET(details, '$.age', 31) WHERE id = 1; +``` + +### PostgreSQL Example: +```sql +UPDATE users SET details = jsonb_set(details, '{age}', '31', false) WHERE id = 1; +``` + +## Indexing JSON Data +JSON fields can be indexed to improve query performance. + +### MySQL: +```sql +ALTER TABLE users ADD INDEX idx_name ((details->'$.name')); +``` + +### PostgreSQL: +```sql +CREATE INDEX idx_name ON users ((details->>'name')); +``` + +## Use Cases +- **Flexible Data Models**: Store varying data structures. +- **API Integration**: Easily handle JSON responses. +- **Data Analysis**: Aggregate and filter nested data. + +## Conclusion +Handling JSON data within SQL combines the flexibility of JSON with the robustness of SQL databases. By leveraging native JSON support, developers can efficiently store, query, and manipulate JSON data, optimizing database operations for modern applications. + +This file provides a comprehensive guide on handling JSON data within SQL, covering essential operations and examples for different databases.