VALUES
VALUES in SQL is a keyword used in the INSERT INTO statement to specify the data that should be inserted into a certain table's columns. Each value is provided in a list enclosed by parentheses and separated by commas, with multiple lists separated by commas to denote multiple rows of data to insert.
Example
INSERT INTO employees (firstname, lastname, age)VALUES ('John', 'Doe', 30);
Output
Query OK, 1 row affected (0.01 sec)
Explanation
The provided MySQL statement inserts a new row into the employees
table. The row’s values for firstname
, lastname
, and age
columns are ‘John’, ‘Doe’, and 30, respectively. The output indicates that the operation was successful, with one row being affected.
Example
INSERT INTO Employee (id, name)VALUES (1, 'John');
Output
INSERT 0 1
Explanation
The INSERT INTO
command adds a new row into the Employee
table with the specified values. In this case, the new employee John
with id
1 is added. The output message INSERT 0 1
indicates that one row is successfully inserted.
Example
CREATE TABLE Customers( CustomerID int, CustomerName varchar(255), ContactName varchar(255), Country varchar(255), Phone varchar(255));
INSERT INTO Customers (CustomerID, CustomerName, ContactName, Country, Phone)VALUES (1, 'Cardinal', 'Tom B. Erichsen', 'Norway', '555-98765');
Output
Commands completed successfully.
Explanation
In this example, a new table named ‘Customers’ is created first with five columns. Then, using the INSERT INTO statement together with the VALUES clause, one new row is added to the ‘Customers’ table. `
Example
INSERT INTO Employees (ID, FirstName, LastName, Age)VALUES (1, 'John', 'Doe', 35);
Output
1 row(s) inserted.
Explanation
The INSERT INTO
statement was used to add a new row in the “Employees” table. The specific data (1, 'John', 'Doe', 35)
was inserted into corresponding columns (ID, FirstName, LastName, Age)
. The output indicates that one row was successfully inserted into the table.