Question

In: Computer Science

Database Design CIW State_Capitals Physical Database Create primary and secondary keys for the attached unfinished physical...

Database Design CIW

State_Capitals Physical Database

Create primary and secondary keys for the attached unfinished physical database design.

CREATE DATABASE STATE_CAPITALS;
GO
USE STATE_CAPITALS;
GO
CREATE TABLE Country(
Country_Code varchar(10) NOT NULL,
Country_Name varchar(50) NOT NULL,
Population int NOT NULL,
Country_Size float NOT NULL
)
GO
CREATE TABLE Region(
Country_Code varchar(10) NOT NULL,
Region_Code varchar(10) NOT NULL,
Region_Name varchar(50) NOT NULL
)
GO
CREATE TABLE State(
Region_Code varchar(10) NOT NULL,
State_Code char(2) NOT NULL,
State_Name varchar(50) NOT NULL,
Date_of_Statehood int NOT NULL,
State_Size float NOT NULL,
State_Population int NOT NULL
)
GO
CREATE TABLE Capital(
State_Code char(2) NOT NULL,
Capital_Code tinyint NOT NULL,
Capital_Name varchar(50) NOT NULL,
Capital_Since smallint NOT NULL,
Land_Area float NOT NULL,
Most_Populous_City bit NOT NULL,
Municipal_Population int NOT NULL,
Metropolitan_Population int NULL,
Note varchar(300) NULL
)
GO

Ensure your submission addresses each of these components:

  • Introduction: Explain the process to create a physical database.
  • Body: The attached DDL statements are used to create the physical database “State_Capitals” that consists of four tables: “Country,” “Region,” “State,” and “Capital.” However, the statements to create the appropriate primary and foreign keys for the tables are missing.
  • Complete the “State_Capitals” physical database by creating the appropriate primary and foreign keys for them.
  • Conclusion: Summarize how DDL is used to create a physical database objects and the use of primary and foreign keys in relational database.

Submit your project in a word document format

Solutions

Expert Solution

  • Primary key :
    • Primary key is used to uniquely identify each record in the table
    • Primary key value can not be duplicate and null
  • Foreign key :
    • Primary key of one table is used as foreign key in another table to maintain relationship between one or more table

Below table shows primary and foreign key for each table

Sr.No Table Name Primary key Foreign key Reference table
1 Country Country_Code -- --
2 Region Region_Code Country_Code Country
3 State State_Code Region_Code Region
4 Capital Capital_Code State_Code State

*********************************

DDL script :

CREATE DATABASE STATE_CAPITALS;  
GO      
USE STATE_CAPITALS;      
GO      
CREATE TABLE Country(  
Country_Code varchar(10) NOT NULL,  
Country_Name varchar(50) NOT NULL,  
Population int NOT NULL,  
Country_Size float NOT NULL   ,
primary key (Country_Code)
);      
GO      
CREATE TABLE Region(      
Country_Code varchar(10) NOT NULL,  
Region_Code varchar(10) NOT NULL,  
Region_Name varchar(50) NOT NULL,
primary key (Region_Code),
foreign key (Country_Code) references Country (Country_Code)
);      
GO      
CREATE TABLE State(      
Region_Code varchar(10) NOT NULL,  
State_Code char(2) NOT NULL,  
State_Name varchar(50) NOT NULL,  
Date_of_Statehood int NOT NULL,  
State_Size float NOT NULL,  
State_Population int NOT NULL,
primary key (State_Code),
foreign key (Region_Code) references region (Region_Code)
);  
GO      
CREATE TABLE Capital(      
State_Code char(2) NOT NULL,  
Capital_Code tinyint NOT NULL,  
Capital_Name varchar(50) NOT NULL,  
Capital_Since smallint NOT NULL,  
Land_Area float NOT NULL,  
Most_Populous_City bit NOT NULL,  
Municipal_Population int NOT NULL,  
Metropolitan_Population int NULL,  
Note varchar(300) NULL,
primary key (Capital_Code),
foreign key (State_Code) references State (State_Code)
);      
GO  


Related Solutions

Create a Database Schema for a hotel reservation system. indicate the Primary Keys, Foreign Keys, and...
Create a Database Schema for a hotel reservation system. indicate the Primary Keys, Foreign Keys, and the one-to-one or one-to-many relationships between the tables. Also describe in a small paragraph the scope of the back-end database, by explaining the different tables and their relations in your schema.
In the world of database design and building it is very important to define Primary keys...
In the world of database design and building it is very important to define Primary keys in each table. The text this week talks about primary keys. What are they and why are they so important to a properly functioning database?
Please create the following tables for a tool rental database with appropriate primary keys & foreign...
Please create the following tables for a tool rental database with appropriate primary keys & foreign keys. Assumptions: 1. Each tool belongs to a category. 2. Each category may have a parent category but the parent category should not have a parent category (so at most two levels). E.g., a Tool A belongs to the electric mower, and electric mowers belong to mowers. Mower has no parent category. 3. Each tool can be rented at different time units. The typical...
Problem 1. Please create the following tables for a tool rental database with appropriate primary keys...
Problem 1. Please create the following tables for a tool rental database with appropriate primary keys & foreign keys. [30 points] Assumptions: Each tool belongs to a category. Each category may have a parent category but the parent category should not have parent category (so at most two levels). E.g., a Tool A belongs to electric mower, and electric mower belongs to mower. Mower has no parent category. Each tool can be rented at different time units. The typical time...
True or False: Logical database design is the process of modifying the physical database design to...
True or False: Logical database design is the process of modifying the physical database design to improve performance. The two major logical database design techniques are conversion of E-R diagrams to relational tables and data normalization. Multivalued attributes are not permitted in unnormalized data. A many-to-many binary relationship in an E-R diagram requires the creation of a total of three tables in a relational database. A one-to-one unary relationship in an E-R diagram requires the creation of a total of...
Create a Database from blank (scratch) for a manager and name it. Create and design a...
Create a Database from blank (scratch) for a manager and name it. Create and design a table and name it. For each fields click and choose proper a data type such as short text and name the field. Make at least three fields. Enter your records. Make sure to add your name as a record. Similarly create two more tables. By design tool, make a relationship between each of two tables at a time and drag a primary key one...
Data Modelling is the primary step in the process of database design. Compare and contrast Conceptual...
Data Modelling is the primary step in the process of database design. Compare and contrast Conceptual data model versus Physical data model. Illustrates with help of example to list down data (entities), relationship among data and constraints on data.
Data Modelling is the primary step in the process of database design. Compare and contrast Conceptual...
Data Modelling is the primary step in the process of database design. Compare and contrast Conceptual data model versus Physical data model. Illustrates with help of example to list down data (entities), relationship among data and constraints on data.
Database __________ which is the logical design of the database, and the database _______ which is...
Database __________ which is the logical design of the database, and the database _______ which is a snapshot of the data in the database at a given instant in time. a) Instance, Schema b) Relation, Schema c) Relation, Domain d) Schema, Instance
Consider the following relational schema about a University (the primary keys are underlined and foreign keys...
Consider the following relational schema about a University (the primary keys are underlined and foreign keys are italic) STUDENT(StudentID, name, major, year, age) CLASS(ClassName, meetsAt, room, LecturerID) ENROLLED(StudentID, ClassName, mark) LECTURER(LecturerID, name, DepartmentID) DEPARTMENT(DepartmentID, name) Write the SQL statements for the following query: B1. Find the age of the oldest student. B2. Find the ID’s of lecturers whose name begins with “K” \ B3. Find the age of the youngest student who is enrolled in Mechatronics. B4. Find the age...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT