The relational schema shown below is part of a hospital database. The primary and foreign keys are highlighted in bold. Patient (patientNo, patName, patAddr, DOB) Ward (wardNo, wardName, wardType, noOfBeds) Admission (patientNo, wardNo, admissionDate) Drug (drugNo, drugName, costPerUnit) Prescribed (patientNo, drugNo, unitsPerDay, startDate, finishDate) Write SQL queries based on the hospital database given above: 1. Create the above tables together with its constraints. 2. Insert some data into the tables to check that the tables created are correct. No limit on how many rows you want to add. Insert Syntax: insert into table_name values (col1_value, col2_value, etc.); 3. List all the patients’ details, alphabetically by name. IF YOU WANT SOME CHALLENGE 4. List all the patients admitted today. (Join between Patient and Admission table)
SQL
SQL stands for Structured Query Language, is a form of communication that uses queries structured in a specific format to store, manage & retrieve data from a relational database.
Queries
A query is a type of computer programming language that is used to retrieve data from a database. Databases are useful in a variety of ways. They enable the retrieval of records or parts of records, as well as the performance of various calculations prior to displaying the results. A search query is one type of query that many people perform several times per day. A search query is executed every time you use a search engine to find something. When you press the Enter key, the keywords are sent to the search engine, where they are processed by an algorithm that retrieves related results from the search index. Your query's results are displayed on a search engine results page, or SER.
The relational schema shown below is part of a hospital
Patient (patientNo, patName, patAddr, DOB)
Ward (wardNo, wardName, wardType, noOfBeds)
Admission (patientNo, wardNo, admissionDate)
Drug (drugNo, drugName, costPerUnit)
Prescribed (patientNo, drugNo, unitsPerDay, startDate, finishDate)
Write SQL queries based on the hospital database given above:
1. Create the above tables together with its constraints.
2. Insert some data into the tables to check that the tables created are correct. No limit on how many rows you want to add.
Insert Syntax:
insert into table_name
values (col1_value, col2_value, etc.);
3. List all the patients’ details, alphabetically by name.
IF YOU WANT SOME CHALLENGE
4. List all the patients admitted today. (Join between Patient and Admission table)
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 7 images