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...
This is the database CREATE TABLE AIRCRAFT ( AC_NUMBER varchar(5) primary key, MOD_CODE varchar(10), AC_TTAF double,...
This is the database CREATE TABLE AIRCRAFT ( AC_NUMBER varchar(5) primary key, MOD_CODE varchar(10), AC_TTAF double, AC_TTEL double, AC_TTER double ); INSERT INTO AIRCRAFT VALUES('1484P','PA23-250',1833.1,1833.1,101.8); INSERT INTO AIRCRAFT VALUES('2289L','DC-90A',4243.8,768.9,1123.4); INSERT INTO AIRCRAFT VALUES('2778V','MA23-350',7992.9,1513.1,789.5); INSERT INTO AIRCRAFT VALUES('4278Y','PA31-950',2147.3,622.1,243.2); /* -- */ CREATE TABLE CHARTER ( CHAR_TRIP int primary key, CHAR_DATE date, AC_NUMBER varchar(5), CHAR_DESTINATION varchar(3), CHAR_DISTANCE double, CHAR_HOURS_FLOWN double, CHAR_HOURS_WAIT double, CHAR_TOT_CHG double, CHAR_OIL_QTS int, CUS_CODE int, foreign key (AC_NUMBER) references AIRCRAFT(AC_NUMBER) ); INSERT INTO CHARTER VALUES(10001,'2008-02-05','2289L','ATL',936,5.1,2.2,354.1,1,10011); INSERT INTO CHARTER VALUES(10002,'2008-02-05','2778V','BNA',320,1.6,0,72.6,0,10016);...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT