Question

1. Complete below SQL statement to find count of records from Customers table. SELECT Country, State,...

1. Complete below SQL statement to find count of records from Customers table.

SELECT Country, State, City, Count(*) AS Count
FROM Customers

2. Add FK on child_table (column1) refrencing from parent_table (column1).

ALTER TABLE child_table

Homework Answers

Answer #1

As the 1st answer is already been provided I will attempt the 2nd answer.

2Ans)

We can use the key constraint FOREIGN KEY and REFERENCES to create a reference from the child_table(column1) to the parent_table(column1).

It is to be noted that the column we are referencing in parent_table should be primary key, It is because all the values in that column should be unique. Else creating a foreign key will create errors.

So the required SQL query is:

ALTER TABLE child_table

ADD FOREIGN KEY(column1) REFERENCES parent_table(column1)

Hope it helps!!!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In SQL working with data types 1. Write a SELECT statement that returns these columns from...
In SQL working with data types 1. Write a SELECT statement that returns these columns from the Instructors table: a. The monthly salary (the AnnualSalary column divided by 12) b. A column that uses the CAST function to return the monthly salary with 1 digit to the right of the decimal point c. A column that uses the CONVERT function to return the monthly salary as an integer d. A column that uses the CAST function to return the monthly...
Use the following tables to answer Q5 and Q6. Tourist (tno, Name, phone, age,loc) Vehicle (Vno,...
Use the following tables to answer Q5 and Q6. Tourist (tno, Name, phone, age,loc) Vehicle (Vno, model, mileage, owner_name, owner_ph)) Rented (tno, Vno) 5. (i)Write an SQL query, to create the table vehicle with following constraints: Vno should begin with second letter ‘v’; Models are one among Thar, X3. Mileage should be above 18 and below 25. No two records can have same phone (ii) Write an SQL query to retrieve the name of the owner who does owns X3...
EMPLOYEE Field Name EMP_ID EMP_LNAME EMP_MI EMP_FNAME EMP_SEX EMP_AGE EMP_SALARY EMP_HIREDATE DEPT_CODE Table: DEPARTMENT DEPT_CODE BIOL...
EMPLOYEE Field Name EMP_ID EMP_LNAME EMP_MI EMP_FNAME EMP_SEX EMP_AGE EMP_SALARY EMP_HIREDATE DEPT_CODE Table: DEPARTMENT DEPT_CODE BIOL CPTR HIST MATH RELB Data Type Text Text Text Text Text Number Currency Date/Time Text DEPT_TITLE Biology Computer Science History Mathematics Religion    Field Name DEPT_CODE DEPT_TITLE Data Type Text Text INSTRUCTIONS Use SQL commands to create the tables and enter the data shown above using MS Access. Write the following SQL statement given below: 1. 2. 3. 4. 5. 6. 7. 8. 9....
Translating MongoDB Queries to SQL - WILL UPVOTE!! 1. Write the equivalent sql queries for all...
Translating MongoDB Queries to SQL - WILL UPVOTE!! 1. Write the equivalent sql queries for all mongoDB queries. The following is an example of what you are asked to do. Assume the collection name is the table name in an sql database. Example: MongoDB Query: db.zips.aggregate([ {$match: {state: "MO"}}, {$group: {_id: "$city", totalPop: {$sum: "$pop"}}}, {$sort: {totalPop: -1}}, {$limit: 10} ]) SQL Result: Select city, SUM(pop) AS "totalPop" From zips Where state = "MO" Group By city Order By SUM(pop)...
From among the choices below, select the proper treatment for each of the following items when...
From among the choices below, select the proper treatment for each of the following items when reconciling a bank account: ADD TO BALANCE PER BANK STATEMENT DEDUCT FROM BALANCE PER BANK STATEMENT ADD TO BALANCE PER DEPOSITOR’S RECORDS DEDUCT FROM BALANCE PER DEPOSITOR’S RECORDS 1. OUTSTANDING CHECKS 2. CHECK DRAWN FOR $1000 IS CHARGED AS $100 3. BANK SERVICE CHARGES 4. A CUSTOMER’S CHECK IS RETURNED FOR LACK OF SUFFICIENT FUNDS 5. DEPOSIT IN TRANSIT NOT RECORDED BY BANK
Customers ID Name Street City Zip email 1 Emily 101 Anza St San Francisco 94118 2...
Customers ID Name Street City Zip email 1 Emily 101 Anza St San Francisco 94118 2 Amy 1 Houston Ave New York 12111 3 John 29 Sunset Blvd Los Angeles 45643 4 Pam 800 Market St San Francisco 94080 5 Sue 400 Muir Ave Redwood City 94598 6 Chris 987 A Ave New York 13111 7 Todd 788 Harrison St San Francisco 94117 Products ID Product_name Price Quantity 1 Metal pen 5.99 20 2 Surge protector 25.99 0 3 pencil...
Save your select statements as a script. Place the semicolon at the end of each SQL...
Save your select statements as a script. Place the semicolon at the end of each SQL statement. Please number your select statements from 1 to 8 in your script and comment out each number. Include your name and student number as a comment at the top of your script. The name of the script has to be Assignment1_JohnSmith. Instead of JohnSmith use your First Name and Last Name. Upload your script trough Blackboard. Use SQL Developer to create the My...
***This is a complete question. Do not tag this as incomplete. Write SQL queries to the...
***This is a complete question. Do not tag this as incomplete. Write SQL queries to the below Relational Database. • Regarding the SQL queries: • Do not use SELECT * in any query. • Do not use any SQL features (including Nullif) that were not covered in this course. • Do not use subqueries IF joins can be used to answer a question. However, some questions may require the use of subqueries. The Movie Database Notes: TheaterNum, MovieNum, and ActorNum...
From among the choices below, select the proper treatment for each of the following items when...
From among the choices below, select the proper treatment for each of the following items when reconciling a bank account: ADD TO BALANCE PER BANK STATEMENT DEDUCT FROM BALANCE PER BANK STATEMENT ADD TO BALANCE PER DEPOSITOR’S RECORDS DEDUCT FROM BALANCE PER DEPOSITOR’S RECORDS a b c d   1. OUTSTANDING CHECKS a b c d   2. CHECK DRAWN FOR $1000 IS CHARGED AS $100 a b c d   3.  BANK SERVICE CHARGES a b c d    4.  A CUSTOMER’S CHECK IS RETURNED FOR LACK OF SUFFICIENT...
1. Consider the following tables in a relational database. Provide the appropriate "SELECT" SQL statement necessary...
1. Consider the following tables in a relational database. Provide the appropriate "SELECT" SQL statement necessary to answer the queries that follow. Primary keys are underlined and foreign key fields have an asterisk at the end of the field. CUSTOMERS (CUST-NO, C-NAME, C-ADDRESS, BALANCE) SALESPERSONS (SP-NO, S-NAME, DATE-EMPLOYED, SALARY) SALES (INVOICE-NO, DATE, CUST-NO*, SP-NO*) a) List the salesperson name and salary for all sales to customers whose balance outstanding is greater than 20000. b) List the names and addresses of...