Question

In: Computer Science

For this week let’s discuss the concepts of primary keys and table indexes. What types of...

For this week let’s discuss the concepts of primary keys and table indexes.

  • What types of data might serve as a valuable index for a table?
  • What types of data would be unsuitable as a primary key?

Give some examples of data types and fields that you might use for certain scenarios and also what types are not good to use.

Solutions

Expert Solution

# To discuss these concepts we suppose primay key as a mapping concept  and index value as array concept.

# So from here you may start thinking about what is array.

# Array-> Is a collection of similar data type , which is used for storage purpose of similar data .

Suppose you have U.S Dollars of different prices from 0-10. (similar data type)

  you wanted to count them how many u have for a particular coin.

for that purpose you can use array

Amount counting

$ 0 -> 0

$ 1 -> 2   

$ 2 -> 3

$ 3 -> 4

$ 4 -> 7

$ 5 -> 8

$ 6 -> 9

$ 7 -> 4   

$ 8 -> 6

$ 9 -> 8

$ 10 -> 2

  

ARRAY

0 2 3 4 7 8 9 4 6 8 2

Index 0 1 2 3 4 5 6 7 8 9 10

Here index work -> coin number.(similar data type)

c++/c++14

#include<iostream>

using namespace std;

int main()

{

int a[11]; // this way you can intilise an array.

for (int i=0;i<11;++i) // loop for iteration

{

cin>>a[i];

}

}

# MAPPING-> suppose we have two array's and after combining both of them we get mapping

KEY POINTS:

1. Primary key -> Is unique , it can't be similar.

2. value of key -> It can be similar or different

Suppose Goku , Ash , Friza and Naruto are friends all of them have different U.S doller ammount

Name Amount

Goku -> $ 450

Ash -> $ 1200

Friza -> $ 900

Naruto -> $ 450

Method->1

we can use two array to store both values

Array-1 store Names

Goku Ash Friza Naruto

Index 0   1 2 3

Array-2 store Amount they have

450 1200 900 450

Index 0   1 2 3

  Method->2

use a single map

primary key value of key
Ash 1200
Friza 900
Goku 450
Naruto 450

Note->mapping has the property to sort accordingly to it's primay key.

use->you can write names and they will come in sorted (Dictionary manner).

program in mapping

Note-> map header file in mendotary

#include<iostream>

#inlcude<map>

using namespace std;

int main()

{

map<string,int> a; // this way you can declare map.

for (int i=0;i<4;++i) // loop for iteration

{

string s;

int amount ;

cout<<"\n Enter name: ";

cin>>s;  

cout<<"Enter amount they have: ";

cin>>amount;

}

}

Disanvantage of using map -> It use more memory as compare to array, that's why use map only in case of storing related data in case of non-relative data use array.


Related Solutions

1. Write CREAT TABLE statements for the following tables (primary keys are underlined, foreign keys are...
1. Write CREAT TABLE statements for the following tables (primary keys are underlined, foreign keys are in italic and bold). Make sure you have all needed constraints and appropriate datatypes for attributes: Student (stID, stName, dateOfBirth, advID, majorName, GPA) Advisor (advID, advName, specialty) 2.  Insert several records in each table.
1. Write CREAT TABLE statements for the following tables (primary keys are underlined, foreign keys are...
1. Write CREAT TABLE statements for the following tables (primary keys are underlined, foreign keys are in italic and bold). Make sure you have all needed constraints and appropriate datatypes for attributes: Student (stID, stName, dateOfBirth, advID, majorName, GPA) Advisor (advID, advName, specialty) 2. Insert several records in each table.
Consider the following three tables, primary and foreign keys. Table Name        SalesPeople Attribute Name                  &nbsp
Consider the following three tables, primary and foreign keys. Table Name        SalesPeople Attribute Name                                Type                                      Key Type EmployeeNumber             Number                               Primary Key Name                                   Character JobTitle                                  Character            Address                                 Character PhoneNumber                     Character YearsInPosition                             Number Table Name        ProductDescription Attribute Name                                Type                                      Key Type                 ProductNumber                Number                               Primary Key                 ProductName                  Character                            ProductPrice                   Number Table Name        SalesOrder Attribute Name                                Type                                      Key Type                 SalesOrderNumber        Number                               Primary Key                 ProductNumber               Number                               Foreign Key                 EmployeeNumber           Number                               Foreign Key                 SalesOrderDate                Date Assume that you...
Consider the following three tables, primary and foreign keys. Table Name        SalesPeople Attribute Name                  &nbsp
Consider the following three tables, primary and foreign keys. Table Name        SalesPeople Attribute Name                                Type                                      Key Type EmployeeNumber             Number                               Primary Key Name                                   Character JobTitle                                  Character            Address                                 Character PhoneNumber                     Character YearsInPosition                             Number Table Name        ProductDescription Attribute Name                                Type                                      Key Type                 ProductNumber                Number                               Primary Key                 ProductName                  Character                            ProductPrice                   Number Table Name        SalesOrder Attribute Name                                Type                                      Key Type                 SalesOrderNumber        Number                               Primary Key                 ProductNumber               Number                               Foreign Key                 EmployeeNumber           Number                               Foreign Key                 SalesOrderDate                Date Assume that you...
Discuss why databases are important in accounting information systems. Describe primary and foreign keys, normalization and...
Discuss why databases are important in accounting information systems. Describe primary and foreign keys, normalization and database cardinalities. Why are each important to the database design? Your initial posting should be 250-500 words and must be submitted by Thursday, 11:59 pm MST, of this week.
Discuss why databases are important in accounting information systems. Describe primary and foreign keys, normalization and...
Discuss why databases are important in accounting information systems. Describe primary and foreign keys, normalization and database cardinalities. Why are each important to the database design? Your initial posting should be 250-500 words and must be submitted by Thursday, 11:59 pm MST, of this week.
Discuss the five main types of regional trade agreements. What are their primary chracteristics?
Discuss the five main types of regional trade agreements. What are their primary chracteristics?
This week let’s discuss integration. 1. Name a company that practices horizontal integration and describe the...
This week let’s discuss integration. 1. Name a company that practices horizontal integration and describe the structure. 2. Name a company that practices vertical integration and describe the structure. 3. In your opinion, which is better to work for? Which offers workers the better opportunity to better yourself? 4. If you owned the business, which would you implement? Think again about the workers opportunities. Does their betterment also mean what’s best for your business? Please number each question and provide...
This week let’s discuss integration. First, name a company the practices horizontal integration. Describe the structure....
This week let’s discuss integration. First, name a company the practices horizontal integration. Describe the structure. Now do the same for a company vertically integrated. In your opinion, which is better to work for? Which offers workers the better opportunity to better yourself? Now, if you owned the business, which would you implement? Think again about the worker's opportunities. Does their betterment also mean what’s best for your business?
•What are the primary types of evidence? Explain
•What are the primary types of evidence? Explain
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT