如何更新 SQL 中的 table?

How can I update the table in SQL?

我创建了一个table叫作Youtuber,代码如下:

create table Channel (
    codChannel int primary key,
    name varchar(50) not null,
    age float not null,
    subscribers int not null,
    views int not null
)

在这个table中,有2个频道:

|codChannel |       name      | age | subscribers |       views |
|     1     |    PewDiePie    | 28  |  58506205   | 16654168214 |
|     2     | Grandtour Games | 15  |       429   |       29463 |

所以,我想将 "Grandtour Games" 的年龄修改为“18”。我怎样才能用 update 做到这一点?
我的代码正确吗?

update age from Grandtour Games where age='18'

alter table 更改模式(添加、更新或删除列或键,诸如此类)。

更新 table 更改 table 中的数据而不更改架构。

所以这两者真的很不一样。

这是你的答案 -

-> ALTER is a DDL (Data Definition Language) statement 
UPDATE is a DML (Data Manipulation Language) statement.


->ALTER is used to update the structure of the table (add/remove field/index etc). 
Whereas UPDATE is used to update data.

希望对您有所帮助!

不,在 update 中,您必须遵循以下顺序:

update tableName set columnWanted = 'newValue' where columnName = 'elementName'

在您的代码中,输入:

update Channel set age=18 where name='Grandtour Games'

以下评论:

/* Channel is the name of the table you'll update

   set is to assign a new value to the age, in your case

   where name='Grandtour Games' is referencing that the name of the Channel you want to update, is Grandtour Games */