当前位置:网站首页>MySQL learning record (2)
MySQL learning record (2)
2022-07-02 21:29:00 【White_ Silence (Learning version)】
1. Create database
For the time being MYSQL

create database shop;
/* Create database */
show databases;
/* Show the current MYSQL Stored database */2. Create table
CREATE TABLE < Table name >
( < Name 1> < data type > < Constraints required for this column > ,
< Name 2> < data type > < Constraints required for this column > ,
.
.
.
< Constraints for this table 1> , < Constraints for this table 2> ,……);
create database shop;
use shop;
CREATE TABLE product(
product_id CHAR(4) NOT NULL,
product_name VARCHAR(100) NOT NULL,
product_type VARCHAR(32) NOT NULL,
sale_price INTEGER,
purchase_price INTEGER,
regist_date DATE,
PRIMARY KEY(product_id)
) ;The syntax is shown in the code , But if you want to create a table under the currently created database , To use use < Database name >, no need USE The complains .

Perform shortcut key sharing :ctrl+enter Execute the currently selected command line , If it is not selected, the current line will be executed
ctrl+shift+enter Execute all commands
ctrl+shift+r Run only the selected statements
3. Naming rules
- Only half width English letters can be used 、 Numbers 、 Underline (_) As a database 、 Table and column names
- The name must start with half letter
- Every field in every table ( That is, each column ) Specify the data type
3.1 Basic types of data
- INTEGER type (INT, Similar to floating point , Double precision )
Used to specify the data type of the column where integers are stored ( Digital ), Can't store decimals .
- CHAR type ( character string =string)
Used to store fixed length strings , When the length of the string stored in the column does not reach the maximum length , Use half space to complement , Because it wastes storage space , So I don't use .
- VARCHAR type ( Variable length string )
Used to store variable length strings , Fixed length string will be supplemented with half width spaces when the number of characters does not reach the maximum length , But variable length strings are different , Even if the number of characters does not reach the maximum length , I don't use half space to make up .
- DATE type ( date )
Used to specify the storage date ( Specific date ) The data type of the column of ( Date type ).
3.2 Setting of data constraints
Constraints are in addition to data types , The function of restricting or appending conditions to the data stored in a column .
NOT NULL yes Non empty constraint , That is, data must be entered in the column .
PRIMARY KEY yes Primary key constraint , Represents that the column is unique , You can get the data of a specific row through this column .
There is no need to restrict
3.3 About table deletion and update syntax
similar stata
- Delete table :drop table < Table name >; (stata :drop Field name )
- Modify table —— The main use of ALTER command
Add columns to the table :alter table < Table name > add column< Definition of columns >;
Delete column from table :alter table< Table name >drop column< Name >;
- Clear the table :truncate table table_name
alter table product add column quality INTEGER;
-- Add a column... To the table , Field called quality
alter table product drop column quality ;
-- Delete a column from the table , Field called quality
drop table product;feeling : At present, the grammar is ok , If someone used a similar language before , It should be easier to learn this .
I watched the tutorial from Alibaba cloud Tianchi , For personal notes only .
边栏推荐
- Add two numbers of leetcode
- 26 FPS video super-resolution model DAP! Output 720p Video Online
- [error record] the command line creates an error pub get failed (server unavailable) -- attempting retry 1 in 1 second
- MySQL learning notes (Advanced)
- [shutter] statefulwidget component (pageview component)
- Hot backup routing protocol (HSRP)
- Welfare | Hupu isux11 Anniversary Edition is limited to hand sale!
- Construction and maintenance of business website [1]
- Plastic granule Industry Research Report - market status analysis and development prospect forecast
- JS modularization
猜你喜欢
![[shutter] shutter layout component (Introduction to layout component | row component | column component | sizedbox component | clipoval component)](/img/45/735431f59a84e9554225a72a551ab8.jpg)
[shutter] shutter layout component (Introduction to layout component | row component | column component | sizedbox component | clipoval component)

In depth research and investment feasibility report of global and Chinese isolator industry, 2022-2028

Report on investment development and strategic recommendations of China's vibration isolator market, 2022-2027
![[hands on deep learning]02 softmax regression](/img/47/eb67ec2c51f6bb7d6b2879b36e769d.jpg)
[hands on deep learning]02 softmax regression

Hot backup routing protocol (HSRP)

Baidu sued a company called "Ciba screen"
![[shutter] the shutter plug-in is used in the shutter project (shutter plug-in management platform | search shutter plug-in | install shutter plug-in | use shutter plug-in)](/img/80/215499c66243d5a4453d8e6206c012.jpg)
[shutter] the shutter plug-in is used in the shutter project (shutter plug-in management platform | search shutter plug-in | install shutter plug-in | use shutter plug-in)

I did a craniotomy experiment: talk about macromolecule coding theory and Lao Wang's fallacy from corpus callosum and frontal leukotomy

Roommate, a king of time, I took care of the C language structure memory alignment
![[dynamic planning] p1220: interval DP: turn off the street lights](/img/b6/405e29ca88fac40caee669a3b7893f.jpg)
[dynamic planning] p1220: interval DP: turn off the street lights
随机推荐
7. Build native development environment
Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of precoated metallic coatings in the global market in 2022
China plastic box market trend report, technological innovation and market forecast
Common routines of compressed packets in CTF
In depth research and investment feasibility report on the global and China active vibration isolation market 2022-2028
Research Report on market supply and demand and strategy of microplate instrument industry in China
[hands on deep learning]02 softmax regression
[error record] the command line creates an error pub get failed (server unavailable) -- attempting retry 1 in 1 second
[shutter] statefulwidget component (bottom navigation bar component | bottomnavigationbar component | bottomnavigationbaritem component | tab switching)
Construction and maintenance of business website [5]
股票开户要找谁?手机开户是安全么?
Construction and maintenance of business websites [10]
Research Report on market supply and demand and strategy of Chinese garden equipment industry
Longest public prefix of leetcode
5 environment construction spark on yarn
One week dynamics of dragon lizard community | 2.07-2.13
Plastic granule Industry Research Report - market status analysis and development prospect forecast
ctf-HCTF-Final-Misc200
Golang embeds variables in strings
2021 v+ Quanzhen internet global innovation and Entrepreneurship Challenge, one of the top ten audio and video scene innovation and application pioneers