{"id":19661000,"url":"https://github.com/programmershahjalal/postgres-sql-assignment","last_synced_at":"2026-03-02T08:32:39.302Z","repository":{"id":259273278,"uuid":"877348087","full_name":"ProgrammerShahJalal/postgres-sql-assignment","owner":"ProgrammerShahJalal","description":null,"archived":false,"fork":false,"pushed_at":"2024-10-23T17:46:20.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-27T03:16:31.207Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ProgrammerShahJalal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-23T13:53:53.000Z","updated_at":"2024-10-23T17:46:24.000Z","dependencies_parsed_at":"2024-10-24T02:28:15.650Z","dependency_job_id":"4c3ee3df-9ad6-4f24-88a9-a00f83d96191","html_url":"https://github.com/ProgrammerShahJalal/postgres-sql-assignment","commit_stats":null,"previous_names":["programmershahjalal/postgres-sql-assignment"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ProgrammerShahJalal/postgres-sql-assignment","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProgrammerShahJalal%2Fpostgres-sql-assignment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProgrammerShahJalal%2Fpostgres-sql-assignment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProgrammerShahJalal%2Fpostgres-sql-assignment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProgrammerShahJalal%2Fpostgres-sql-assignment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ProgrammerShahJalal","download_url":"https://codeload.github.com/ProgrammerShahJalal/postgres-sql-assignment/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProgrammerShahJalal%2Fpostgres-sql-assignment/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29995912,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-02T01:47:34.672Z","status":"online","status_checked_at":"2026-03-02T02:00:07.342Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T16:06:07.951Z","updated_at":"2026-03-02T08:32:39.283Z","avatar_url":"https://github.com/ProgrammerShahJalal.png","language":null,"readme":"# Postgres SQL Assignment\n\n## 1. Explain the primary key and foreign key concepts in PostgreSQL.\n\n### Primary Key:\n\n- **Primary Key**: A unique identifier for each row in a table. It ensures that no two rows have the same value and that the value is always present.\n- **Foreign Key**: Links two tables by referring to the primary key in another table. It ensures that the data is related and consistent.\n\nExample:\n\n```sql\nCREATE TABLE customers (\n    id SERIAL PRIMARY KEY,\n    name VARCHAR(100)\n);\n\nCREATE TABLE orders (\n    order_id SERIAL PRIMARY KEY,\n    customer_id INT REFERENCES customers(id)\n);\n```\n\n## 2. What is the difference between the VARCHAR and CHAR data types?\n\n- **VARCHAR**: Stores variable-length character strings, optimizing storage for varying text lengths.\n- **CHAR**: Stores fixed-length character strings, requiring a predefined maximum length. If the data is shorter, it fills in the extra space with blank spaces.\n\n## 3. Explain the purpose of the WHERE clause in a SELECT statement.\n\nThe WHERE clause filters records when querying data. It allows us to get only the rows that meet a condition.\n\nExample:\n\n```sql\nSELECT * FROM products WHERE price \u003e 100;\n```\n\n## 4. What are the LIMIT and OFFSET clauses used for?\n\n- **LIMIT**: Limits the number of rows returned in the result set.\n- **OFFSET**: Skips a specified number of rows before starting to return results.\n  Example:\n\n```sql\nSELECT * FROM products LIMIT 10 OFFSET 20;\n```\n\n## 5. How can you perform data modification using UPDATE statements?\n\nThe UPDATE statement is used to change data in a table. We can update specific columns for selected rows using a WHERE clause.\n\nExample:\n\n```sql\nUPDATE products SET price = 150 WHERE id = 1;\n```\n\n## 6. What is the significance of the JOIN operation, and how does it work in PostgreSQL?\n\nA JOIN combines rows from two or more tables based on a related column. It’s useful when we need to get data from multiple tables in one query.\n\nExample:\n\n```sql\nSELECT customers.name, orders.order_id\nFROM customers\nJOIN orders ON customers.id = orders.customer_id;\n```\n\n## 7. Explain the GROUP BY clause and its role in aggregation operations.\n\nThe GROUP BY clause groups rows that have the same values in a specified column. It’s used with aggregate functions like SUM, COUNT, MAX, MIN, and AVG.\n\nExample:\n\n```sql\nSELECT category, COUNT(*) FROM products GROUP BY category;\n```\n\n## 8. How can you calculate aggregate functions like COUNT, SUM, and AVG in PostgreSQL?\n\nAggregate functions are used to perform calculations on sets of data. For example:\n\n- COUNT(): Counts rows.\n- SUM(): Adds up values.\n- AVG(): Calculates the average.\n\nExample:\n\n```sql\nSELECT COUNT(*), SUM(price), AVG(price) FROM products;\n```\n\n## 9. What is the purpose of an index in PostgreSQL, and how does it optimize query performance?\n\nAn index is like a shortcut for searching data. It speeds up queries by allowing the database to quickly find rows instead of scanning the entire table.\n\n## 10. Explain the concept of a PostgreSQL view and how it differs from a table.\n\nA view is like a saved query. It looks like a table but doesn’t store data. It displays results from other tables and updates automatically when the underlying data changes.\n\nExample:\n\n```sql\nCREATE VIEW active_customers AS\nSELECT * FROM customers WHERE active = true;\n```\n\n## License\n\nAll rights reserved by **Md Shah Jalal**.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprogrammershahjalal%2Fpostgres-sql-assignment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprogrammershahjalal%2Fpostgres-sql-assignment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprogrammershahjalal%2Fpostgres-sql-assignment/lists"}