Retrieving Data From A Number of Tables (Relations) : Use Select From Where
Retrieving Data From A Number of Tables (Relations) : Use Select From Where
Retrieving Data From A Number of Tables (Relations) : Use Select From Where
Some tales of a database are logically lined using primary keys and foreign keys.
For example DEPARTMENT tables and EMPLOYEE tables are logically linked using the
Primary Key (PK) and Foreign Key (FK).
DEPARTMENT
EMPLOYEE
Example: We shall list department name and first name of employee using Transact-SQL command.
Since these data are coming from two tables, we have to join them temporally within the
Transact-SQL.
PK FK
1
The temporary Teble created on the computer memory after joining tables.
But, If you are to list Primary key attribute and Foreign key attribute you need tables names.
Example:
NOTE: JOINING process in a database query is an expensive / time taking process. It involves
searching and matching values under the PK and FK. Tables with 500000 records might
take about 15 minutes to list the answer to a query. Therefore INDEX files are used to
support searching process.
2
QUESTION: Do we really have to join tables to get results?
ORDER BY clause
Example:
GROUP BY Clause
Example
The following command list the departments starting with the letter A.
select *
from DEPARTMENT
WHERE Dept_Name like 'A%'
Please Read
http://msdn.microsoft.com/en-us/library/ms173454.aspx
3
EXERCISES:
Write the Transact-SQL code to create the tables in the following ER Model. You must include
appropriate date types for the attributes and the constraints for PKs and FKs.