How to insert the data into a specific field of a _mysql_table?

Asked

Viewed 1,538 times

1

I have a table called company, with the fields name, addressee, city, telephone, email and link.

How should I proceed to enter a value in the field link that is empty?

  • What you want to know is which SQL command to use?

3 answers

4

You can run a UPDATE, but beware ! apparently you don’t have a ID single for each field. I did the UPDATE selecting by name, and this is not correct at this time, however it will work, you can change by the field you want to select, follow the code:

UPDATE empresa
SET link = 'https://seusite.com'
WHERE nome = 'Leonardo'

THE RIGHT WAY TO DO IT

A table with auto_increment and a Primary key.

CREATE TABLE empresa(
   ID int NOT NULL AUTO_INCREMENT,
   nome varchar(255) NOT NULL,
   endereco varchar(255),
   cidade varchar(255),
   telefone varchar(255),
   email varchar(255),
   link varchar(255),
   PRIMARY KEY (ID)
);

To give INSERT, is the same thing as your table, but you do not need to set the ID because it is automatic.

THE UPDATE would look like this:

UPDATE empresa
SET link = 'https://seusite.com'
WHERE ID = 1

So you wouldn’t change the city of ALL Leonardo, just Leonardo with ID = 1 that is unique.

1

UPDATE "table" SET link = "value" WHERE

0

That way you could already update this data, but as Leonardo mentioned, a table without ID is worrisome !

UPDATE empresa
SET link = 'https://link.com'
WHERE nome = 'Linhares'
  • But no problem, there is only one table, so there is no need for ID, understood????

  • I understand, anyway this is called good practices, as you said, being a single table will probably not miss, but other than this you can use any other field in the Where clause and perform the update in the link column or as you wish (y)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.