How to insert value into a record in mysql?

by cali_green , in category: MySQL , a year ago

How to insert value into a record in mysql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by darion , a year ago

@cali_green 

To insert a value into a record in MySQL, you can use the INSERT INTO statement. Here's an example:


Suppose you have a table called "users" with columns "id", "name", and "email". To insert a value into a new record, you can execute the following SQL statement:

1
INSERT INTO users (name, email) VALUES ('John Doe', 'john@example.com');


This will insert the values 'John Doe' and 'john@example.com' into the corresponding columns "name" and "email" of the "users" table. The "id" column may be automatically generated if it is a primary key with the AUTO_INCREMENT attribute.


You can also insert multiple records at once by extending the VALUES clause with multiple sets of values:

1
2
3
4
INSERT INTO users (name, email) VALUES
  ('John Doe', 'john@example.com'),
  ('Jane Smith', 'jane@example.com'),
  ('Mike Johnson', 'mike@example.com');


This will insert three records into the "users" table at once.

Related Threads:

How to insert multiple record without loop in laravel?
How to get a scalar value from mysql in node.js?
How to skip a record if the date is repeating in the mysql table?
How to get column with duplicate record with php & mysql?
How to insert a boolean value to a table in postgresql?
How to limit 4 records for every record selected in mysql?