当前位置:网站首页>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 .
边栏推荐
猜你喜欢

How to establish a decentralized community in Web3

Record the fluent to solve the problem of a renderflex overflowed by 7.3 pixels on the bottom

【机器学习】朴素贝叶斯对文本分类--对人名国别分类
![[CS231N]Lecture_2:Image Classification pipelin](/img/4f/de56b071560ada746c587a9dbc5f02.jpg)
[CS231N]Lecture_2:Image Classification pipelin

想要快速成长,先要经历重大打击!

普源示波器实际的使用效果怎么样

SQL注入 Less34(POST型宽字节注入+布尔盲注)

科大讯飞笔试

阿里云CDN实践

SQL注入 Less38(堆叠注入)
随机推荐
Ukrainian officials: half of Ukrainian agricultural products are exported through the Danube port
Ordinary practice of JS DOM programming
SQL注入 Less38(堆叠注入)
DHCP and PPPoE protocols and packet capture analysis
Make trouble fishing day by day
hcip实验(14)
Chapter 7: drawing rotating cubes
Aimbetter insight into your database, DPM and APM solutions
04. Default value of toref
DHCP和PPPoE协议以及抓包分析
局域网添加DNS服务器进行域名解析
openresty 请求鉴权
Clearing of applet component timer
HCIP(14)
In Kingbase, the user is specified to search the schema by default, or the user cannot use the function under the public schema
Part 8: creating camera classes
HYDAC overflow valve db08a-01-c-n-500v
Hcip experiment (15)
[leetcode] maximum depth of binary tree
Differences of display values