Concept explainers
Primary Key:
A Primary Key in a
Example:
Students in Universities are assigned a unique registration number. Therefore, in a STUDENT database table, the attribute “reg_no” acts as primary key.
Foreign Key:
Foreign Key is a column in a relational database table which provides a relation between two tables. It provides a cross reference between tables by pointing to primary key of another table.
Example:
In STUDENT database table, the attribute “reg_no” acts as primary key and in COURSE database table in which the student selects his or her course, the same “reg_no” acts as foreign key for the STUDENT table.
Given database tables:
Table Name: EMPLOYEE
EMP_CODE | EMP_TITLE | EMP_LNAME | EMP_FNAME | EMP_INITIAL | EMP_DOB | STORE_CODE |
1 | Mr. | Williamson | John | W | 21-May-84 | 3 |
2 | Ms. | Ratula | Nancy | 09-Feb-89 | 2 | |
3 | Ms. | Greenboro | Lottie | R | 02-Oct-81 | 4 |
4 | Mrs. | Rumpersfro | Jennie | S | 01-Jun-71 | 5 |
5 | Mr. | Smith | Robert | L | 23-Nov-59 | 3 |
6 | Mr. | Renselear | Cary | A | 25-Dec-85 | 1 |
7 | Mr. | Ogallo | Roberto | S | 31-Jul-82 | 3 |
8 | Ms. | Johnson | Elizabeth | I | 10-Sep-88 | 1 |
9 | Mr. | Eindsmar | Jack | W | 19-Apr-55 | 2 |
10 | Mrs. | Jones | Rose | R | 06-Mar-66 | 4 |
11 | Mr. | Broderick | Tom | 21-Oct-72 | 3 | |
12 | Mr. | Washington | Alan | Y | 08-Sept-74 | 2 |
13 | Mr. | Smith | Peter | N | 25-Aug-64 | 3 |
14 | Ms. | Smith | Sherry | H | 25-May-66 | 4 |
15 | Mr. | Olenko | Howard | U | 24-May-64 | 5 |
16 | Mr. | Archialo | Barry | V | 03-Sep-60 | 5 |
17 | Ms. | Grimaldo | Jeanine | K | 12-Nov-70 | 4 |
18 | Mr. | Rosenburg | Andrew | D | 24-Jan-71 | 4 |
19 | Mr. | Rosten | Peter | F | 03-Oct-68 | 4 |
20 | Mr. | Mckee | Robert | S | 06-Mar-70 | 1 |
21 | Ms. | Baumann | Jennifer | A | 11-Dec-74 | 3 |
Table Name: STORE
STORE_CODE | STORE_NAME | STORE_YTD_SALES | REGION_CODE | EMP_CODE |
1 | Access Junction | 1003455.76 | 2 | 8 |
2 | Database Corner | 1421987.39 | 2 | 12 |
3 | Tuple Charge | 986783.22 | 1 | 7 |
4 | Attribute Alley | 944568.56 | 2 | 3 |
5 | Primary Key Point | 2930098.45 | 1 | 15 |
Table Name: REGION
REGION_CODE | REGION_DESCRIPT |
1 | EAST |
2 | WEST |
Trending nowThis is a popular solution!
Chapter 3 Solutions
Database Systems: Design, Implementation, & Management
- Delete the OWNER_INDEX 3 index from the OWNER table.arrow_forwardAdd two columns to the EMPLOYEES table. One column, named EmpDate, contains the date of employment for each employee, and its default value should be the system date. The second column, named EndDate, contains employees date of termination.arrow_forwardWhich of the following characters can be used in a table name? a. b. ( c. % d. !arrow_forward
- What is the maximum number of PRIMARY KEY constraints allowed for a table? a. 1 b. 2 c. 30 d. 255arrow_forwardTable name : tblFilm Attributes: FilmReleaseDate, FilmRunTimeMinutes (For the conditions) Write a query to increase the budget of all films released between 1933 and 1970 and whose FilmRunTimeMinutes is more than the average FilmRunTimeMinutes by 50%.arrow_forwardList the names of all Staff members who hold a faculty position and have a salary of $45,000 or less. Show their names as their first name, followed by a space, and then their last name but sort the list alphabetically by last name and then first name. Hint: Check out the Position column in the Staff table. All staff members who do not hold a faculty position will get a bonus this year equal to 5% of their salary. List the names, current salary, and bonus amount for each Staff member (non-faculty) who is due a bonus. Show your list in order with the person receiving the highest bonus first.arrow_forward
- List unique first (first_name) and last names (last_name) of customers (CUSTOMER table) who rented a movie (RENTAL table) between '2011-06-01' and '2012-01-01’ (rental_date). Sort by last_name. The common key is CUSTOMER_ID.arrow_forwardcode of create table and insert table only pleasearrow_forwardWe have the following tables which creates statement are1. create table supplier(S_NO int identity(1,1), SUP_ID varchar(50) primary key,SUP_NAME varchar (50), SUP_ADD varchar (50), SUP_NIC int, rank int)2. create table Product(Prod_ID varchar(50) primary key,Prod_Name varchar(50),[Price/Unit] float)3. create table Orders(Ord_ID varchar(50) primary key,Prod_ID varchar(50),Qty int,Totalrate int,SUP_ID varchar (50))Write the Queries using Joins on above tables1. List of all supplier that palced order2. SELECT S.S_NO,S.SUP_NAME,S.SUP_ADD,S.RANK,S.SUP_ID FROM ORDERS O INNERarrow_forward
- O d. COMMIT This clause in SQL join is based on all columns in the two tables that have the same name. a. USING clause O b. ON clause O c. OUTER JOIN Od. NATURAL JOINarrow_forwardFrom the database scheme write the query(all tables are empty) 1) Insert your name and your phone as a new tenant 2) Delete your phone number from the table tenant. 3) Create a new contract lease for you. 4) Delete the contract that you created. 5) List the city name, city population and country name. 6) List the cities that have the letters “re” in any part of the name; 7) List the tenant name contract number, rent price, when the contract rent price is bigger equal 500 and lower equal 1000. 8) List all columns from apartments with the services offered (all columns from service). 9) List the building address, the city name and the country name for the building in Canada. 10) List the name of the user with the city name and country name, ordering by name of user.arrow_forwardWhen constructing a table at the column level, what is the maximum number of columns that may be defined as a primary key before the table becomes too large? (See the tables in the JustLee Books database for further information.)arrow_forward
- Database Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781305627482Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningA Guide to SQLComputer ScienceISBN:9781111527273Author:Philip J. PrattPublisher:Course Technology Ptr
- Database Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781285196145Author:Steven, Steven Morris, Carlos Coronel, Carlos, Coronel, Carlos; Morris, Carlos Coronel and Steven Morris, Carlos Coronel; Steven Morris, Steven Morris; Carlos CoronelPublisher:Cengage Learning