Data Application Master's SQL Basic Tutorial Sharing 9-Data Operation

Chapter 3 Data Operations and Functions

(The basic element in the database is the data. This chapter will introduce you to how SQL operates on specific data, as well as the knowledge of functions in SQL)


 

1. Data manipulation

The movement to create "data"

1. Insert data

【Introduction to knowledge points】

In addition to query, data manipulation is also an important content in SQL. In SQL, there are three basic statements: INSERT, UPDATE, and DELETE to add, modify, and delete data.
First, let's introduce INSERT, that is, inserting data. We can insert a new column of data, insert specified data in a specified column, or insert data from other tables into a table.
The general usage of INSERT is as follows:

-- Insert a new column of data into the table
INSERT INTO 表
VALUES (value1, value2, value3);

-- insert data into the specified column
INSERT INTO table (column 1, column 2)
VALUES (value1, value2);

-- Insert data from other tables to the target table
INSERT INTO table1 (column1,column2)
SELECT (column1,column2) FROM table2
WHERE[clause];

 

Note: SQL statements are case-insensitive, but the data itself is case-sensitive.

【Example】

Add a new student to our student table, where ID and Credit are integer types, others are string types, and ID and SName cannot be empty, pay attention to the order, pay attention to view the data values ​​in our SQL statement.

INSERT INTO student
VALUES (20160015,'Maya','Female','Botany',28);

 

2. Update data

【Introduction to knowledge points】

UPDATE can modify and update the data in the table. Its general usage is as follows:

UPDATE table SET column = new value
WHERE column = some value;

 

【Example】

Change the gender of Martin in the student table to Male, and fill in the vacant data. He is a Botany major with 26 credits.
Martin's student number is 20160013.

student
SET Sex = 'Male',
    Major = 'Botany',
    Credit = 28
WHERE ID = 20160013; -- specify the row to modify by ID

 

3. Delete data

DELETE is used to perform deletion. It is very effective and decisive. It can be used to delete the entire row of data, but it cannot delete the data of a certain column.
Use DELETE with caution, once the data is deleted, then...
We can use to delete one or more rows of data specified:

DELETE FROM 表
WHERE[clause];

 

【Example】

Delete the data of the classmate Maya, her student number is 20160015.
Deletes the specified data by ID.

DELETE FROM student
WHERE ID = 20160015;

 

 

To be continued below. . . . . .

 

Welcome to visit our official website:

http://www.datanew.com/datanew/homepage

http://www.lechuangzhe.com/homepage

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326328650&siteId=291194637