Question

In: Computer Science

Create table, create primary and foreign key constraints. Create index on the table to satisfy a...

Create table, create primary and foreign key constraints. Create index on the table to satisfy a query with aggregate functions.

Solutions

Expert Solution

Note: Using SQL*Plus

            __________ ---> Primary key

            _ _ _ _ _ _ _ _ ---> Foreign key

Database:

Department (dname, dnumber)

Employee (ssn, name, salary, sex, address, dno)

To Create two tables (referencing and referenced)

1. Creating referenced table Department first:

    Create table Department (

    dname varchar(15) unique not null,

    dnumber int ,

    Primary key (dnumber));

desc Department;

2. Inserting data into Department Table

     Insert into Department values ('Research',1);

     Insert into Department values ('HR',2);

    Insert into Department values ('Development',3);

     Insert into Department values ('Testing',4);

select * from department;

3. Creating referencing table Employee first

   Create table Employee(

   ssn char(9),

   name varchar(15) not null,

   salary decimal(10,2),

   sex char,

   address varchar(30),

   dno int not null,

   primary key(ssn),

   foreign key(dno) references Department(dnumber));

  

desc Employee

4. Inserting values into Employees

   Insert into Employee values('emp001','Ram',30000,'M','RT Nagar, Blore',3);

   Insert into Employee values('emp002','Sudha',75000,'F','Hebbal, Blore',2);

   Insert into Employee values('emp003','Ravi',20000,'M','Hebbal, Blore',4);

   Insert into Employee values('emp004','Rohan',80000,'M','RT Nagar, Mysore',1);

   Insert into Employee values('emp005','Amar',35000,'M','MG Road, Mysore',3);

   Insert into Employee values('emp006','Anil',45000,'M','MG Road, Noida',3);

   Insert into Employee values('emp007','Tanya',35000,'F','Yelahanka, Blore',3);

   Insert into Employee values('emp008','Kavita',50000,'F','Baglur, Blore',1);

   Insert into Employee values('emp009','John',45000,'M','RT Nagar, Blore',4);

  

select * from employee;

5. Create index on employyes table on salary column to use aggregate functions

   Create Index idx on Employee(salary);

  

6. Use aggregate function

   select sum(salary) from employee;

  


Related Solutions

Assuming Database is not providing Referential Integrity Constraints support i-e Primary key, foreign key and Unique...
Assuming Database is not providing Referential Integrity Constraints support i-e Primary key, foreign key and Unique key, your task is to design a database engine with your own built in Referential integrity rules implementation and you need that only one database connection is maintained which an application should access. Recommend proper design pattern used for the stated problem. Give reasons for selecting that pattern, create complete class diagram for the solution. The class diagram should also show the methods of...
create table node( node_id integer primary key, node_color varchar(10)); create table edge( edge_id integer primary key,...
create table node( node_id integer primary key, node_color varchar(10)); create table edge( edge_id integer primary key, origin_id integer, destination_id integer, foreign key (origin_id) references node(node_id), foreign key (destination_id) references node(node_id)); write an SQL query that lists all those nodes that have edges with a destination node that has color 'red'.
Consider the following table definitions create table node( node_id integer primary key, node_color varchar(10)); create table...
Consider the following table definitions create table node( node_id integer primary key, node_color varchar(10)); create table edge( edge_id integer primary key, origin_id integer, destination_id integer, foreign key (origin_id) references node(node_id), foreign key (destination_id) references node(node_id)); What is the result of the following query? select node_id, node_color, destination_id from node, edge; An inner join of the tables node and edge that lists origin node_id and node_color together with the node_id of the destination node for all those nodes that have outgoing...
Create a table in SQL with foreign key reference: 1.Create the three tables without any columns...
Create a table in SQL with foreign key reference: 1.Create the three tables without any columns 2.Alter the tables to add the columns 3.Alter the tables to create the primary and foreign keys
what is super key,  candidate key, and primary key, and foreign key in terms of database? and...
what is super key,  candidate key, and primary key, and foreign key in terms of database? and plz provide some examples, thanks.
1. Use SQL to create a polyinstantiated table including a primary key and a unique constraint...
1. Use SQL to create a polyinstantiated table including a primary key and a unique constraint 2.Use SQL to insert multiple records for each security classification with the same ID. You must have 4 classifications. 3.Use SQL to create 4 schemas, one for each security classification 4.Use SQL to create a view in each schema that restricts the records to those belonging to a particular security classification and restricts the columns to only those columns that have relevant data. 5.Select...
1a) i) Explain the candidate key, primary key and foreign key with suitable examples [6] ii)...
1a) i) Explain the candidate key, primary key and foreign key with suitable examples [6] ii) Draw a suitable ER diagram to show the “IS-A” relationship between subtype and supertype [5] iii) Briefly explain the recursive relationship with a suitable example. [2]
Identify every possible primary key, candidate key, and foreign key for the following relations. Separate each...
Identify every possible primary key, candidate key, and foreign key for the following relations. Separate each key using a semicolon to avoid confusion. Assumptions: MIScompany has branches located in several states within the United States. A customer can be an individual or organization. driverId is the driving license number, ssno is the social security number and upc is the universal product code. Any equipment is rented and returned at the same branch. A customer can be a manufacturer and vice...
Create a table with name “S_YOURStudentID” with the following fields with required constraints. Screenshots are to...
Create a table with name “S_YOURStudentID” with the following fields with required constraints. Screenshots are to be attached.                                                                                               For example, if your botho student id is 1212121, your table name should be “S_1212121”.                                   Student id Student Name Age Gender City Course name Module Name Internal mark 1 Internal mark 2 Internal mark 3 Total internal mark Insert minimum 10 records/rows to the table. Input the data based on Question 5. Screenshots are to be attached.                                                                                                                              Create two users...
what does a primary key and foreign key relates to? Which drive does a magnet damage...
what does a primary key and foreign key relates to? Which drive does a magnet damage the most what the Raid differences ? what a NIC does what is NAS and what's it used for and how it can be used in a network setting which device has a built in antenna what RF is used for (Radio Frequency )
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT