Creation, insertion, and deletion of data tables in the database

Preface

The database is an important part of the operation of the data table. To realize the operation of the data table, you must understand the relevant operations of the SQL language

One, create a data table

Create data table is still used to create, the specific template is:

create table student(
name varchar(30),           //后面的数据为定义长度
id int(10) primary key,     //primary key定义为该类型为数据表组件
age int(5) not null         //not null定义该行不能为空
);

The data table after creation is as shown in the figure below. It can be seen that the primary key must not be empty:
Insert picture description here

Two, insert data for the data table

Insert usedinsert into database name (row to be inserted) values ​​(corresponding data);, The specific code is:

insert into student(name,id,age) values("小白",2,6);

After the operation is completed, the data table will have such a row of data:

Insert picture description here

Three, find data

The four selects used to find data are completed. The specific code format is:

select * from student;   //星号代表查找表中全部的数据,
select id from student;

The example of the second line in this example is:
Insert picture description here

Fourth, delete the data in the data table

Delete the data in the data table using delete, the specific code is:

delete from student where id=2;  //where后面跟的是一个条件,来确定删除的具体位置

Delete the result (because there is only one row of data, the table becomes empty):
Insert picture description here

to sum up

The data in the database can be combined to complete these operations in actual application operations.

Guess you like

Origin blog.csdn.net/xinzhilinger/article/details/109215317