{"id":29916767,"url":"https://github.com/mennasayed46/c43_g01_db07","last_synced_at":"2025-08-02T05:03:50.307Z","repository":{"id":305013658,"uuid":"1016373274","full_name":"MennaSayed46/C43_G01_DB07","owner":"MennaSayed46","description":" A set of SQL problem-solving tasks","archived":false,"fork":false,"pushed_at":"2025-07-17T18:01:43.000Z","size":119,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-17T20:42:50.478Z","etag":null,"topics":["sql","sql-database","sql-problem-solving","sql-problems","sql-server","sql-server-management-studio","sql-stored-procedures","sql-tasks","sql-triggers"],"latest_commit_sha":null,"homepage":"","language":"TSQL","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/MennaSayed46.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,"zenodo":null}},"created_at":"2025-07-08T23:20:08.000Z","updated_at":"2025-07-17T18:01:46.000Z","dependencies_parsed_at":"2025-07-17T23:17:04.412Z","dependency_job_id":"d7e7d684-85d3-474f-b63a-10da167bba73","html_url":"https://github.com/MennaSayed46/C43_G01_DB07","commit_stats":null,"previous_names":["mennasayed46/c43_g01_db07"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/MennaSayed46/C43_G01_DB07","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MennaSayed46%2FC43_G01_DB07","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MennaSayed46%2FC43_G01_DB07/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MennaSayed46%2FC43_G01_DB07/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MennaSayed46%2FC43_G01_DB07/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MennaSayed46","download_url":"https://codeload.github.com/MennaSayed46/C43_G01_DB07/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MennaSayed46%2FC43_G01_DB07/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268337976,"owners_count":24234538,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"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":["sql","sql-database","sql-problem-solving","sql-problems","sql-server","sql-server-management-studio","sql-stored-procedures","sql-tasks","sql-triggers"],"created_at":"2025-08-02T05:01:30.697Z","updated_at":"2025-08-02T05:03:50.186Z","avatar_url":"https://github.com/MennaSayed46.png","language":"TSQL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SQL Server Project – Stored Procedures \u0026 Triggers\n\n## 📁 Databases Used:\n- `ITI`\n- `MyCompany`\n- `IKEA_Company`\n\n---\n\n## ✅ Part 01 – Stored Procedures\n\n### 1. [ITI DB] Show Number of Students per Department\nCreate a stored procedure to display the number of students in each department.\n\n### 2. [MyCompany DB] Check Employees in Project 100\n- If number of employees ≥ 3 → Display: `\"The number of employees in the project 100 is 3 or more\"`\n- If less → Display: `\"The following employees work for the project 100\"` + list of their first and last names\n\n### 3. [MyCompany DB] Replace an Employee in a Project\nCreate a stored procedure that accepts:\n- Old Employee Number\n- New Employee Number\n- Project Number  \nThe procedure updates the `Works_On` table to reflect the replacement.\n\n---\n\n## ✅ Part 02 – General Utility Procedures\n\n### 1. Sum of Range\nStored procedure that calculates the **sum** of a given number range.\n\n### 2. Circle Area\nStored procedure that calculates the **area of a circle** from a given **radius**.\n\n### 3. Age Category\nStored procedure that determines the **age category**:\n- `\u003c 18` → Child\n- `18 ≤ Age \u003c 60` → Adult\n- `≥ 60` → Senior\n\n### 4. Max, Min, Avg of Numbers\nStored procedure that takes a set of numbers (e.g., `'5,10,15,20,25'`) and returns:\n- Maximum\n- Minimum\n- Average\n\n---\n\n## ✅ Part 03 – Triggers on `ITI` DB\n\n### 1. Prevent Insert on Department\nTrigger that prevents inserting into the `Department` table.  \nShows message: `\"You can’t insert a new record in this table\"`.\n\n### 2. StudentAudit Table\nCreate a new table `StudentAudit`:\n- `ServerUserName`\n- `Date`\n- `Note`\n\n### 3. Insert Trigger on Student Table\nAfter a new student is inserted:\n- Log into `StudentAudit` table with:\n  - Username\n  - Date\n  - Note format:  \n    `\"[username] Insert New Row with Key = [Student Id] in table [Student]\"`\n\n### 4. Instead of Delete Trigger on Student Table\nWhen a delete is attempted:\n- Log into `StudentAudit` table with:\n  - Username\n  - Date\n  - Note format:  \n    `\"try to delete Row with id = [Student Id]\"`\n\n---\n\n## ✅ Part 04 – Triggers and Auditing\n\n### [MyCompany DB] Prevent Employee Insert in March\nTrigger on `Employee` table to **prevent insertions** during **March**.\n\n### [IKEA_Company DB] Audit Budget Updates\nCreate `Audit` table with columns:\n- `ProjectNo`, `UserName`, `ModifiedDate`, `Budget_Old`, `Budget_New`\n\nTrigger on `Project` table that:\n- Detects updates on the `Budget` column\n- Logs old and new values into the `Audit` table with username and date\n\n---\n\n## ℹ️ Notes\n- Ensure each stored procedure and trigger includes proper error handling and validation.\n- Use meaningful names and follow best practices for SQL development.\n- Test each procedure/trigger independently to ensure correct behavior.\n\n## 📦 Download IKEA_Company_DB\n\nIf you'd like to use the **IKEA_Company_DB ||ITI DB || MyCompany** for practicing the Views section, you can download it from the link below:\n\n🔗 [Download IKEA DB](https://drive.google.com/file/d/1WULxidId0fJwl6-4eSraZoqAFSAd_LbZ/view?usp=sharing)\n🔗 [Download ITI DB](https://drive.google.com/file/d/1CKTyVY98kAuZESL0wN05CV1_207HMcB0/view?usp=sharing)\n🔗 [Download MyCompany DB](https://drive.google.com/file/d/1R1q5i1DBYYRkCIlz1Ev-qeKKhQ8pOb77/view?usp=sharing)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmennasayed46%2Fc43_g01_db07","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmennasayed46%2Fc43_g01_db07","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmennasayed46%2Fc43_g01_db07/lists"}