Question

SQL Homework exercises: 1. Write INSERT statements that add two rows to the Members table for...

SQL Homework exercises:

1.

Write INSERT statements that add two rows to the Members table for member IDs 1 and 2, two rows to the Groups table for group IDs 1 and 2, and three rows to the Group_Membership table: one row for member 1 and group 2; one for member 2 and group 1; and one for member 2 and group 2. Then, write a SELECT statement that joins the three tables and retrieves the group name, member last name, and member first name.

2.

Write an INSERT statement that adds another row to the Groups table. This statement should use the NEXTVAL pseudo column to get the value for the next group ID from the sequence that you created in exercise 1. Then, write a SELECT statement that gets all of the data for all of the rows in the Groups table to make sure your sequence worked correctly.

3.

Write an ALTER TABLE statement that modifies the Groups table so the group name in each row has to be unique. Then, re-run the INSERT statement that you used in exercise 2 to make sure this works.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Members( mem_id, first_name, last_name)
Groups( grp_id , name)
Group_Mmebership( mem_id, grp_id)

1.

INSERT INTO Members ( mem_id, first_name, last_name)
VALUES ( 1 , 'Tom', 'Kala' );

INSERT INTO Members ( mem_id, first_name, last_name)
VALUES ( 2 , 'Matti', 'Erichsen' );

INSERT INTO Groups ( grp_id , name)
VALUES (1, 'abc');

INSERT INTO Groups ( grp_id , name)
VALUES (1, 'def');

INSERT INTO Group_Membership ( mem_id, grp_id )
VALUES (1, 2);

INSERT INTO Group_Membership ( mem_id, grp_id )
VALUES (2, 1);

INSERT INTO Group_Membership ( mem_id, grp_id )
VALUES (2, 2);

SELECT G.name, M.first_name, M.last_name
FROM Groups_Memebership P
INNER JOIN Members M ON M.mem_id = P.mem_id
INNER JOIN Groups G ON G.grp_id = P.grp_id;

2.

INSERT INTO Groups ( grp_id , name)
VALUES ( grp_seq.NEXTVAL, 'ijk');

SELECT * FROM Groups;


3.

ALTER TABLE Groups
ADD UNIQUE (name);


INSERT INTO Groups ( grp_id , name)
VALUES ( grp_seq.NEXTVAL, 'ijk');

Add a comment
Know the answer?
Add Answer to:
SQL Homework exercises: 1. Write INSERT statements that add two rows to the Members table for...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • this is sql developer question I just need the format of how to answer question! Create...

    this is sql developer question I just need the format of how to answer question! Create sequences (2) that can be used to number the member ID and group ID values starting with 3 (since you already have 1 and 2). Write an INSERT statement that adds another row to the Groups table, make up a group name. Use the NEXTVAL pseudo column to get the value for the next group ID from the sequence that you created in #5....

  • 3. Write a script that adds rows to the database that you created in exercise 2....

    3. Write a script that adds rows to the database that you created in exercise 2. Add two rows to the Users and Products tables. Add three rows to the Downloads table: one row for user 1 and product 2; one row for user 2 and product 1; and one row for user 2 and product 2. Use the SYSDATE function to insert the current date into the download_date column. Use the sequences created in the previous exercise to get...

  • 2. Write a script that implements the following design: In the Downloads table, the user_id and...

    2. Write a script that implements the following design: In the Downloads table, the user_id and product_id columns are the foreign keys. Create these tables in the ex schema. Create the sequences for the user_id, download_id, and product_id columns. Include a PL/SQL script to drop the table or sequence if it already exists. Include any indexes that you think are necessary. 3. Write a script that adds rows to the database that you created in exercise 2. Add two rows...

  • 1. Write an INSERT statement that adds this row to the Categories table: CategoryName: Brass Code...

    1. Write an INSERT statement that adds this row to the Categories table: CategoryName: Brass Code the INSERT statement so SQL Server automatically generates the value for the CategoryID column. 2. Write an UPDATE statement that modifies the row you just added to the Categories table. This statement should change the Category Name column to “Woodwinds”, and it should use the CategoryID column to identify the row. 3.Write an INSERT statement that adds this row to the Products table: ProductID:...

  • WRITE A SQL QUERY SQL SERVER Write a SELECT statement that returns one column from the...

    WRITE A SQL QUERY SQL SERVER Write a SELECT statement that returns one column from the Customers table named FullName that joins the LastName and FirstName columns. --       Format this column with the last name, a comma, a space, and the first name like this: --       Doe, John --       Sort the result set by last name in ascending sequence. --       Return only the contacts whose last name begins with a letter from M to Z. --  ...

  • Write SQL authorization statements on the employee table as per the following requirements: Employee (id, name,...

    Write SQL authorization statements on the employee table as per the following requirements: Employee (id, name, job_name, dept_name, salary) - You have three managers with manager1, manager2 and manager3 user ids. All of them are members of the role manager. - All managers have the same privileges: select, insert, update, delete. - No managers can transfer his privileges on the employee table.

  • l want to insert statement inside the table student on My SQL program the latest version...

    l want to insert statement inside the table student on My SQL program the latest version but there is an error l am not able determine how to applied or insert a row as: Steps In each of these queries you’re shown the columns to display in your result. Make your column headers look exactly like the example shown. All these queries use the Starter database. 0. Even if you downloaded it for the previous assignment, to make sure you...

  • Which SQL statement retrieves the EmployeeName and City columns from the Employees table? O LIST EmployeeName,...

    Which SQL statement retrieves the EmployeeName and City columns from the Employees table? O LIST EmployeeName, City ON Employees; O FIND EmployeeName, City ON Employees; SELECT EmployeeName, City FROM Employees; O RETRIEVE EmployeeName, City FROM Employees; Which SQL statement finds the different cities in which national parks reside with no duplicate rows listed? SELECT DISTINCT city FROM natlpark ORDER BY city; O ORDER BY natlpark DISTINCT city; O ORDER BY city FROM natlpark; O SELECT city FROM natlpark ORDER BY...

  • Insert the bottom two rows to each table we made in class and update the two...

    Insert the bottom two rows to each table we made in class and update the two in gray in stock and product tables. Provide your SQL code in notepad or word. You can include a screen shot of your select statements showing database populated with your name in ure showing your account Product Product Name Manufacturer 1 102 103 509 Product Product Description Ergonomic keyboard with rest pad HP Model 3456 5x7 inch monitor with stylus Series 5 Pink 32G...

  • 1.What is the return value if the user try to do the following: SELECT TRUNC (65.73,-2)...

    1.What is the return value if the user try to do the following: SELECT TRUNC (65.73,-2) FROM DUAL; Select one: a. 60 b. 00 c. 0 d. 600 2.Supposed that the user uses the ff SELECT statement: what will be the possible output. SELECT GRADE AS STUDENT MARK FROM GRADE_REPORT; Select one: a. Error because of the keyword AS. b. Error because of missing “” mark. c. Will display the column GRADE rename as STUDENT MAK d. Will display all...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT