当前位置:网站首页>MySQL learning record (3)
MySQL learning record (3)
2022-07-02 21:29:00 【White_ Silence (Learning version)】
- Update of data
UPDATE < Table name >
SET < Name > = < expression > [, < Name 2>=< expression 2>...];
WHERE < Conditions >;
-- Optional , It's very important .
ORDER BY Clause ; -
- Optional LIMIT Clause ; -- Optional
-- Modify all registration times ( Here we should connect them to make a sentence )
UPDATE product
SET regist_date = '2009-10-10';
-- Only modify the unit price of some goods
UPDATE product
SET sale_price = sale_price * 10
WHERE product_type = ' Kitchenware ';
--WHERE Is the condition , Select the desired operation object that meets the conditions . UPDATE= to update , Use UPDATE When setting WHERE Conditions , Otherwise, it is the modification of the overall situation .
-- Single column update
-- take ID by 008 The date of the product of is changed to null NULL
-- Number the item as 0008 The data of ( Ball pen ) The registration date of is updated to NULL
UPDATE product
SET regist_date = NULL
WHERE product_id = '0008';
-- Multi column update
UPDATE product
SET sale_price = sale_price * 10,
purchase_price = purchase_price / 2
WHERE product_type = ' Kitchenware ';
Only unset Only columns with non empty constraints and primary key constraints can be cleared to NULL.** If the column with the above constraints is updated to NULL, Will report a mistake .
2.INSERT sentence ( Insert )
Create a new table first productins
CREATE TABLE productins
(product_id CHAR(4) NOT NULL,
product_name VARCHAR(100) NOT NULL,
product_type VARCHAR(32) NOT NULL,
sale_price INTEGER DEFAULT 0,
purchase_price INTEGER ,
regist_date DATE ,
PRIMARY KEY (product_id)); INSERT Basic syntax :INSERT INTO < Table name > ( Column 1, Column 2, Column 3, ……) VALUES ( value 1, value 2, value 3, ……);
-- Contains a list of columns INSERT INTO productins (product_id, product_name, product_type, sale_price, purchase_price, regist_date) VALUES ('0005', ' pressure cooker ', ' Kitchenware ', 6800, 5000, '2009-01-15'); -- Omit the list INSERT INTO productins VALUES ('0005', ' pressure cooker ', ' Kitchenware ', 6800, 5000, '2009-01-15');
When inserting a full column , You can omit column names , Directly write the corresponding data to be inserted
-- Multiple lines INSERT ( DB2、SQL、SQL Server、 PostgreSQL and MySQL Multi line insertion )
INSERT INTO productins VALUES ('0002', ' Punch ',
' Office Supplies ', 500, 320, '2009-09-11'),
('0003', ' motion T T-shirt ', ' clothes ', 4000, 2800, NULL),
('0004', ' kitchen knife ', ' Kitchenware ', 3000, 2800, '2009-09-20');
-- Insert multiple lines with () and , Segmentation INSERT The statement wants to assign... To a column NULL When the value of , Can be directly in VALUES Clause in the list of values NULL. Want to insert NULL Columns must not be set NOT NULL constraint .
INSERT INTO productins (product_id, product_name, product_type,
sale_price, purchase_price, regist_date) VALUES ('0006', ' Fork ',
' Kitchenware ', 500, NULL, '2009-09-20'); You can also insert default values into the table ( Initial value ). You can create a table by CREATE TABLE Set... In the statement DEFAULT Constraints to set default values .
Join in DEFAULT 0, The default value is 0
CREATE TABLE productins
(product_id CHAR(4) NOT NULL,
( A little )
sale_price INTEGER
( A little ) DEFAULT 0, -- The default value of the sales unit price is set to 0;
PRIMARY KEY (product_id)); 4. Copy the data
Use INSERT … SELECT Statement to copy data from other tables .
-- Copy the data in the item table to the item table
INSERT INTO productocpy (product_id, product_name, product_type, sale_price, purchase_price, regist_date)
SELECT product_id, product_name, product_type, sale_price,
purchase_price, regist_date
FROM Product;
-- Find the source table data (FROM) Use SELECT Select data retrieval and then use INSERT Insert into the replication table - DML : insert data
STARTTRANSACTION;
INSERT INTO product VALUES('0001', 'T shirt ', ' clothes ', 1000, 500, '2009-09-20');
INSERT INTO product VALUES('0002', ' Punch ', ' Office Supplies ', 500, 320, '2009-09-11');
INSERT INTO product VALUES('0003', ' motion T T-shirt ', ' clothes ', 4000, 2800, NULL);
INSERT INTO product VALUES('0004', ' kitchen knife ', ' Kitchenware ', 3000, 2800, '2009-09-20');
INSERT INTO product VALUES('0005', ' pressure cooker ', ' Kitchenware ', 6800, 5000, '2009-01-15');
INSERT INTO product VALUES('0006', ' Fork ', ' Kitchenware ', 500, NULL, '2009-09-20');
INSERT INTO product VALUES('0007', ' Clean the board ', ' Kitchenware ', 880, 790, '2008-04-28');
INSERT INTO product VALUES('0008', ' Ball pen ', ' Office Supplies ', 100, NULL, '2009-11-11');
COMMIT;
use shop;
-- /* Create a ADDRESSBOOK surface */
create TABLE Addressbook (
regist_no INTEGER NOT NULL,
name varchar(128) NOT NULL,
address VARCHAR(256) NOT NULL,
tel_no CHAR(10),
mail_address CHAR(20),
primary key (regist_no)
);
-- Add a column to the table Fixed length string (8) Non empty constraint
ALTER TABLE Addressbook add column postal_code CHAR(8) NOT NULL;
-- Delete the table
truncate table Addressbook;I watched the tutorial from Alibaba cloud Tianchi , For personal notes only .
边栏推荐
- Spend more time with your computer on this special holiday, HHH
- Highly qualified SQL writing: compare lines. Don't ask why. Asking is highly qualified..
- [shutter] shutter layout component (opacity component | clipprect component | padding component)
- Get weekday / day of week for datetime column of dataframe - get weekday / day of week for datetime column of dataframe
- Adding data to the head or tail of the rar file can still decompress normally
- rwctf2022_ QLaaS
- I did a craniotomy experiment: talk about macromolecule coding theory and Lao Wang's fallacy from corpus callosum and frontal leukotomy
- Analysis of enterprise financial statements [4]
- Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of power management units in the global market in 2022
- Select function
猜你喜欢

Unexpectedly, there are such sand sculpture code comments! I laughed

Investment strategy analysis of China's electronic information manufacturing industry and forecast report on the demand outlook of the 14th five year plan 2022-2028 Edition
![[error record] the command line creates an error pub get failed (server unavailable) -- attempting retry 1 in 1 second](/img/6e/c82ff02a249b5d275a4589120a197a.jpg)
[error record] the command line creates an error pub get failed (server unavailable) -- attempting retry 1 in 1 second
![[fluent] dart technique (independent main function entry | nullable type determination | default value setting)](/img/cc/3e4ff5cb2237c0f2007c61db1c346d.jpg)
[fluent] dart technique (independent main function entry | nullable type determination | default value setting)
![[shutter] statefulwidget component (image component | textfield component)](/img/4b/8e54607939989f994303ce5d922331.gif)
[shutter] statefulwidget component (image component | textfield component)

Basic knowledge of tree and binary tree (detailed illustration)

It is said that this year gold three silver four has become gold one silver two..
![[question brushing diary] classic questions of dynamic planning](/img/31/fcd8230f809d6178f11e7095c1ef94.jpg)
[question brushing diary] classic questions of dynamic planning

Redis sentinel cluster working principle and architecture deployment # yyds dry goods inventory #

Interested parties add me for private chat
随机推荐
2021 v+ Quanzhen internet global innovation and Entrepreneurship Challenge, one of the top ten audio and video scene innovation and application pioneers
JDBC | Chapter 4: transaction commit and rollback
[fluent] dart function (function composition | private function | anonymous function | function summary)
Talk about macromolecule coding theory and Lao Wang's fallacy from the perspective of evolution theory
Plastic granule Industry Research Report - market status analysis and development prospect forecast
Write the content into the picture with type or echo and view it with WinHex
[C language] [sword finger offer article] - replace spaces
One week dynamics of dragon lizard community | 2.07-2.13
AES encryption CBC mode pkcs7padding filling Base64 encoding key 32byte iv16byte
Research Report on the overall scale, major manufacturers, major regions, products and applications of friction dampers in the global market in 2022
7. Build native development environment
China microporous membrane filtration market trend report, technological innovation and market forecast
Go cache of go cache series
[shutter] statefulwidget component (floatingactionbutton component | refreshindicator component)
Record the problems encountered by nodejs asynchronism
Go language learning summary (5) -- Summary of go learning notes
Research Report on market supply and demand and strategy of China's plastic pump industry
Sword finger offer (I) -- handwriting singleton mode
[shutter] statefulwidget component (create statefulwidget component | materialapp component | scaffold component)
What is the difference between programming in real work and that in school?