How to insert value into a record in mysql?

by cali_green , in category: MySQL , 5 months ago

How to insert value into a record in mysql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by darion , 5 months 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', '[email protected]');


This will insert the values 'John Doe' and '[email protected]' 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', '[email protected]'),
  ('Jane Smith', '[email protected]'),
  ('Mike Johnson', '[email protected]');


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