MySQL practice practice || database creation and additions, deletions, and changes

Foreword:

        Long time no see, I, Hu Hansan, are back§(* ̄▽ ̄*)§

        The blogger has not updated the article for a while, what are you doing? As a hard-working student party (plus a senior dog who is about to graduate), of course, he is going through the ruthless destruction of his graduation and all kinds of miscellaneous homework. T_T, so if there is no post for half a month in the future It’s normal too (don’t ask, asking is just bald for graduation இ௰இ

        Well, stop complaining, the reason why the blogger posted this article is not to commemorate anything, just because the content of this article is blog! host! when! forward! want! Write! of! do! industry! (Yes, I wrote it to make up the number of articles, akimbo.jpg) Of course, I will still write the detailed process carefully, in order to take care of myself this cabbage (white and cabbage hhh

        Praise for being a cabbage but studying hard (the old father shows a gratified smile hhhhh

Requirement 1: First, start MySQL on the computer, establish a database TEST in MySQL, and perform various operations required later. All SQL operations are performed on the database established here.

For other learning operations, please refer to the MySQL study notes I wrote earlier~

​​​​​​​​​​MySQL study notes 2|| MySQL service related operations (start, stop, log in, log out) and error solutions_Inochigohan's blog - CSDN blog​​​​​​​

Practical process:


 Requirement 2: Run the statements in the create.sql and populate.sql files respectively in the newly created database test to create the data tables customers, orderitems, vendors and orders.

Practical process:


Requirement 3: Write a MySQL statement to retrieve all customer names (cust_name) from the customers table; write a MySQL statement to retrieve all columns in the customers table, and then write another SELECT statement to retrieve only the customer ID (cust_id) and name.

Practical process:


 Requirement 4: Using a subquery, return a list of customers whose purchase price (item_price) does not exceed $20. Tip: You need to use the orderitems table to find matching order numbers (order_num), then use the orders table to retrieve the customer IDs (cust_id) for those matching orders.

Practical process:

Method 1: Use subquery (as required by the title)

 Method 2: Use table join


Requirement 5: Use INSERT and the specified column to add your personal information to the customers table, where the student ID, name and email address are added to the cust_id, cust_name and cust_email columns respectively, and the values ​​of other columns of personal information are set to NULL. Retrieve all column information of the customers table after the new column is added.

Practical process:


Requirement 6: Use a MySQL statement to update all addresses in the United States, including the vendor state (vend_state value in the vendors table where the vendor_country value is USA) and the customer state (cust_state in the customers table), so that they are all lowercase.

Practical process:


Requirement 7: Question 4.4 asks you to add yourself to the customers table. Now please delete yourself and the customer whose ID (cust_id) is 10001. TIP: Make sure to use a WHERE clause, test it with a SELECT before using it in a DELETE, or you'll delete all customer information.

Practical process:

 The above is the whole content of the article~~

Since this article was written by the blogger himself according to the homework requirements, if the passers-by are fortunate enough to do the same homework with the blogger, I hope the viewers will try to do it by themselves first, and then refer to the blogger's answer. After all , only the knowledge in one's head is priceless (Yuan Fang, are you right ( •̀ .̫ •́ )✧Love&Peace

Guess you like

Origin blog.csdn.net/Inochigohan/article/details/120914707