当前位置:网站首页>Can the MySQL create statement be used to create a table structure and append new records
Can the MySQL create statement be used to create a table structure and append new records
2022-07-28 22:22:00 【Yisu cloud】
mysql create Statement can be used to create a table structure and append new records
This article “mysql create Statement can be used to create a table structure and append new records ” Most people don't quite understand the knowledge points of the article , So I made up the following summary for you , Detailed content , The steps are clear , It has certain reference value , I hope you can gain something after reading this article , Let's take a look at this article “mysql create Statement can be used to create a table structure and append new records ” Article bar .
You can't .CREATE The function of the statement is to create a table structure , But new records cannot be added , Adding a new record can use INSERT sentence .CREATE Statement can be used to create a new table in the database , And specify the attributes and constraints of the data column ; But the new table is an empty table , Need to use INSERT Statement to append a new record .INSERT Statement is used to insert one or more rows of tuple data into the existing table in the database .
The operating environment of this tutorial :windows7 System 、mysql8、Dell G3 The computer .
“create Statement is used to create a table structure and append new records ”, It's wrong. .
CREATE The function of the statement is to create a table structure , But new records cannot be added , Adding a new record can use INSERT sentence .
CREATE sentence
CREATE Statement can be used to create a new table in the database ; The process of creating a data table is to specify the attributes of data columns , At the same time, it is also the implementation of data integrity ( Including physical integrity 、 Referential integrity and domain integrity ) The process of constraint .
The syntax format of creating a table is :
CREATE TABLE < Table name > ([ Table definition options ])[ Table options ][ Partition options ];
among ,[ Table definition options ] The format is :
< Name 1> < type 1> [,…] < Name n> < type n>
CREATE TABLE More command syntax , It is mainly created and defined by the table (create-definition)、 Table options (table-options) And partition options (partition-options) Made up of .
Here is a simple example of creating a new table , And then focus on CREATE TABLE Some main syntax knowledge points in the command .
CREATE TABLE The main syntax and instructions of the sentence are as follows :
CREATE TABLE: Used to create a table with a given name , Must have table CREATE Authority .
< Table name >: Specify the name of the table to be created , stay CREATE TABLE Then give , Must comply with identifier naming rules . The table name is specified as db_name.tbl_name, To create tables in a specific database . Whether or not there is a current database , Can be created in this way . When creating a table in the current database , It can be omitted db-name. If you use a quoted distinguished name , The database and table names should be quoted separately . for example ,'mydb'.'mytbl' It's legal. , but 'mydb.mytbl' illegal .
< Table definition options >: Table creation definition , By column name (col_name)、 Definition of columns (column_definition) And possible null values 、 Integrity constraints or table indexes consist of .
The default is , The table is created into the current database . If the table already exists 、 There is no current database or the database does not exist , There will be errors .
Example : establish tb_courses Data sheet
CREATE TABLE tb_courses(course_id INT NOT NULL AUTO_INCREMENT,course_name CHAR(40) NOT NULL,course_grade FLOAT NOT NULL,course_info CHAR(100) NULL,PRIMARY KEY(course_id));

Check it out. tb_emp1 Data from data sheets
SELECT * FROM tb_courses;

You can see that the new table does not contain data . To insert a record, you need to use INSERT sentence .
INSERT sentence
INSERT Statement can insert one or more rows of tuple data into the existing tables in the database .
INSERT There are two grammatical forms of sentences , Namely INSERT…VALUES Statement and INSERT…SET sentence .
1) INSERT…VALUES sentence
INSERT VALUES The grammar format of is :INSERT INTO < Table name > [ < Name 1> [ , … < Name n>] ]VALUES ( value 1) [… , ( value n) ];
The grammar is as follows .
< Table name >: Specifies the name of the table being manipulated .
< Name >: Specify the name of the column to insert the data . If you insert data into all the columns in the table , Then all column names can be omitted , Direct adoption INSERT< Table name >VALUES(…) that will do .
VALUES or VALUE Clause : This clause contains the list of data to insert . The order of the data in the data list corresponds to the order of the columns .
2) INSERT…SET sentence
The grammar format is :
INSERT INTO < Table name >SET < Name 1> = < value 1>, < Name 2> = < value 2>, …
This statement is used to specify the corresponding column values directly to some columns in the table , The column name of the data to be inserted is in SET Clause ,col_name For the specified column name , After the equal sign is the specified data , And for unspecified Columns , The column value is specified as the default value for that column .
stay MySQL in , Use single INSERT Statements handle multiple insertions rather than using multiple INSERT Faster sentences . When using a single INSERT When a statement inserts multiple rows of data , Just enclose each row of data in parentheses .
Example : Add values to all fields in the table
stay tb_courses Insert a new record into the table ,course_id The value is 1,course_name The value is “Network”,course_grade The value is 3,info The value is “Computer Network”.
INSERT INTO tb_courses(course_id,course_name,course_grade,course_info)VALUES(1,'Network',3,'Computer Network');

You can see that the record is inserted successfully . When inserting data , It specifies tb_courses All fields of the table , Therefore, a new value will be inserted for each field .
That's about “mysql create Statement can be used to create a table structure and append new records ” The content of this article , I believe we all have a certain understanding , I hope the content shared by Xiaobian will be helpful to you , If you want to know more about it , Please pay attention to the Yisu cloud industry information channel .
边栏推荐
- [Ruiji takeout] day05 package management business development
- DHCP and PPPoE protocols and packet capture analysis
- The applet listens for the target node to appear on the screen
- Why is 0.1 + 0.2 not equal to 0.3? How to solve this problem?
- Alibaba cloud CDN practice
- What is a prime factor? In number theory, a prime factor (prime factor or prime factor) refers to a prime number that can divide a given positive integer
- SQL injection less34 (post wide byte injection + Boolean blind injection)
- CDN工作原理
- Desai wisdom number - line chart (stacking area chart): ranking of deposits of different occupational groups in the proportion of monthly income in 2022
- 【云原生之kubernetes】在kubernetes集群下的映射外部服务—Eendpoint
猜你喜欢

Jmeter 安装第三方插件 Plugins Manager

HCIP(12)

HCIP(8)

Basic introduction of Rockwell AB PLC rslogix digital quantity IO module

CDN working principle

From Web3 to web2.5, is it backward or another way?
![[NLP] generate word cloud](/img/c4/4e9707bba58732a90d1c30312719a3.png)
[NLP] generate word cloud

SQL injection less42 (post stack injection)

AimBetter洞察您的数据库,DPM 和 APM 解决方案

使用百度EasyDL实现明厨亮灶厨师帽识别
随机推荐
gprs网络指的是什么
SQL注入 Less38(堆叠注入)
40. Combined sum II
ssh 免密码登录
【机器学习】朴素贝叶斯对文本分类--对人名国别分类
Sword finger offer II 053. Medium order successor in binary search tree (medium binary search tree DFS)
array_ diff_ The method of not comparing array values when Assoc element is an array
Learning notes and summary of C language programming specification
The person in charge of Tencent cloud database borrowed 100 million yuan to speculate in stocks? Insider: the amount is not true
Establishment of Ruiji takeout development environment
什么是时间复杂度
Written examination summary record
LVS+KeepAlived高可用部署实战应用
Typeof principle
Intranet penetration learning (III) horizontal movement of domain - planning tasks
Mysql内置函数
Jmeter 安装第三方插件 Plugins Manager
Brief introduction to PCB materials
Future trend of defi in bear market
Add DNS server to LAN for domain name resolution