Question

In: Computer Science

Write an algorithm to find the primary key and foreign key(s)? (Every programming language is accepted.)

Write an algorithm to find the primary key and foreign key(s)?

(Every programming language is accepted.)

Solutions

Expert Solution

querry to find Primary Key and Foreign Key is

SELECT ac.table_name,
column_name,
position,
ac.constraint_name,
DECODE (constraint_type, 'P', 'Primary Key', 'Foreign Key') key_type,
(SELECT ac2.table_name
FROM all_constraints ac2
WHERE AC2.CONSTRAINT_NAME = AC.R_CONSTRAINT_NAME)
fK_to_table
FROM all_cons_columns acc, all_constraints ac
WHERE acc.constraint_name = ac.constraint_name
AND acc.table_name = ac.table_name
AND CONSTRAINT_TYPE IN ('P', 'R')
--AND ac.table_name = 'ACCOUNT' (your table here)
ORDER BY table_name, constraint_type, position;


Algorithm


Select TABLE_NAME   

select COLUMN_NAME   

select POSITION   

select CONSTRAINT_NAME

KEY_TYPE

FK_TO_TABLE

ACCOUNT ACCOUNT_ID 1 ACCOUNT_PK Primary Key   
ACCOUNT ACCOUNT_TYPE_ID 1 ACCOUNT_FK3 Foreign Key ACCOUNT_TYPE
ACCOUNT RELATED_ACCOUNT_ID 1 ACCOUNT_FK5 Foreign Key ACCOUNT
ACCOUNT SERVICE_DB_ID 1 ACCOUNT_FK1 Foreign Key SERVICE_DATABASE
ACCOUNT IMPLEMENTING_AGENCY_ID 1 ACCOUNT_FK4 Foreign Key IMPLEMENTING_AGENCY


Related Solutions

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...
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.
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes...
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes the final score of a baseball game. Use a loop to read the number of runs scored by both teams during each of nine innings. Display the final score afterward. Submit your design, code, and execution result via file, if possible
What is the primary goal in using a scripting language for programming work?
What is the primary goal in using a scripting language for programming work?
Write a program that performs a merge-sort algorithm without using a recursion. c++ programming language(Only #inlclude...
Write a program that performs a merge-sort algorithm without using a recursion. c++ programming language(Only #inlclude <iostream>)
LISP Programming Language Write a Bubble Sort program in the LISP Programming Language called “sort” that...
LISP Programming Language Write a Bubble Sort program in the LISP Programming Language called “sort” that sorts the array below in ascending order.  LISP is a recursive language so the program will use recursion to sort. Since there will be no loops, you will not need the variables i, j, and temp, but still use the variable name array for the array to be sorted.             Array to be sorted is 34, 56, 4, 10, 77, 51, 93, 30, 5, 52 The...
Write pseudocode for quick find algorithm anf quick union algorithm Write pseudocode for quick find algorithm...
Write pseudocode for quick find algorithm anf quick union algorithm Write pseudocode for quick find algorithm and quick union algorithm
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]
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 )
GPA calculator in C language To understand the value of records in a programming language, write...
GPA calculator in C language To understand the value of records in a programming language, write a small program in a C-based language that uses an array of structs that store student information, including name, age, GPA as a float, and grade level as a string (e.g., “freshmen,” etc.). Note:Code and Output Screenshots
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT