Skip to content
Advertisement

How can I update the table in SQL?

I’ve created a table called Youtuber, the code is below:

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

In this table, there are 2 channels:

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

So, I want to edit the age of “Grandtour Games” to “18”. How can I do that with update?
Is my code right?

update age from Grandtour Games where age='18'

Advertisement

Answer

No, in update, you’ll have to follow this sequence:

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

In your code, put this:

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

Comments below:

/* 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 */

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement