How to insert the data into a specific field of a _mysql_ table?

1
I have a table named company, with the fields name , address , city and link .

How do I enter a value in the link field that is empty?

    
asked by anonymous 14.08.2017 / 15:25

3 answers

4

You can run UPDATE , but beware! apparently you do not have a single ID for each field. I have done UPDATE selecting by name, and this is not correct on that occasion, 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 MAKE

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 , it is the same as your table, however you do not need to set ID because it is automatic.

The UPDATE would look like this:

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

So you would not change the city of ALL Leonardo, only Leonardo with ID = 1 that is unique.

    
14.08.2017 / 15:38
1

UPDATE "table" SET link = "value" WHERE

    
14.08.2017 / 15:28
0

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

UPDATE empresa
SET link = 'https://link.com'
WHERE nome = 'Linhares'
    
14.08.2017 / 17:23