The VALUES keyword in SQL is used to insert data into a table. It is typically used with the INSERT INTO statement to specify the data that you want to insert into a table.
Syntax:
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
Example:
Suppose you have a table called employees with the columns id, name, and age.
INSERT INTO employees (id, name, age)
VALUES (1, 'John Doe', 30);
You can also insert multiple rows in one query:
INSERT INTO employees (id, name, age)
VALUES
(2, 'Jane Smith', 28),
(3, 'Samuel Adams', 35);
Important Notes:
-
The number of values in the
VALUESclause must match the number of columns specified in theINSERT INTOclause. -
You can omit the column names if you're providing values for all columns in the same order as they are defined in the table:
INSERT INTO employees VALUES (4, 'Alice Brown', 25); -
Some SQL databases allow you to use the
DEFAULTkeyword to insert default values for certain columns:INSERT INTO employees (id, name) VALUES (5, 'Bob Green');
In this case, if the age column has a default value or is nullable, it will be automatically handled by the database.
No comments:
Post a Comment