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 TABLE Hotel ( roomNumber     INTEGER         PRIMARY KEY, type                  CHAR(1
CREATE TABLE Hotel ( roomNumber     INTEGER         PRIMARY KEY, type                  CHAR(10)         NOT NULL, rate                   INTEGER         NOT NULL, -- CONSTRAINT IC1 CHECK (type IN ('suite', 'king', 'queen')), CONSTRAINT IC2 CHECK (type <> 'suite' OR rate > 200), CONSTRAINT IC3 CHECK (NOT (type = 'king' AND (rate < 80 OR rate > 220))), CONSTRAINT IC4 CHECK (NOT (type = 'queen' AND rate >= 100)) ); which 8 of these inserts will be rejected only 8 are rejected 1. INSERT INTO Hotel VALUES (21, 'king', 90); 2. INSERT INTO Hotel...
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.
Discuss database constraints: Primary key, check, and referential integrity constraints? Give an example for each. What...
Discuss database constraints: Primary key, check, and referential integrity constraints? Give an example for each. What are the three types of database design situations? Briefly describe the various tasks of the primary key. Explain the concept of a foreign key. Explain the concept of a surrogate key. Explain the essence of normalization that is implemented through the use of normal forms. What is SQL? Explain why it is important to learn SQL. What is the purpose of normalization? What conditions...
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...
create table candidate ( cand_id   varchar(12) primary key,   -- cand_id name       varchar(40)           --...
create table candidate ( cand_id   varchar(12) primary key,   -- cand_id name       varchar(40)           -- cand_nm ); create table contributor ( contbr_id   integer primary key, name       varchar(40),           -- contbr_nm city     varchar(40),           -- contbr_city state       varchar(40),           -- contbr_st zip       varchar(20),           -- contbr_zip employer   varchar(60),           -- contbr_employer occupation   varchar(40)           -- contbr_occupation ); create table contribution ( contb_id   integer primary key, cand_id   varchar(12),           --...
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]
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT