It is possible to write the INSERT INTO statement in two ways:
1. Specify both the column names and the values to be inserted:
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
2. If you are adding values for all the columns of the table, you do not need to specify the column names in the SQL query. However, make sure the order of the values is in the same order as the columns in the table. Here, the INSERT INTO syntax would be as follows:
INSERT INTO table_name
VALUES (value1, value2, value3, ...);
-- if you want to insert values in all column
-- values must be assigned to that column
INSERT INTO table_name
VALUES
(value1, value2, value3, ...);
-- ^ ^ ^ ^
-- (column1, column2, column3, ...)
-- the same arrangement
-- the following statement inserts values value1, value2 and value3
-- into columns column1, column2, column3 respectively
INSERT INTO table_name (column1, column2, column3)
VALUES(value1, value2, value3);
-- the following statement inserts the values in order into
-- all the columns of the table
INSERT INTO table_name
VALUES(value1, value2, value3);
INSERT INTO sakila.actor
(first_name, last_name) # column names to insert into
VALUES
("Ryan", "Desmond"); # values to insert into those columns (in the same order)
# in SQL, the hashtag or pound sign is the comment symbol, just FYI
INSERT INTO name (...)
VALUES (...)
Used alongside the INSERT INTO keyword to add new values to a table.
Example: Adds a new car to the cars table.
INSERT INTO cars (name, model, year)
VALUES ('Ford', 'Fiesta', 2010);
-- sql insert using string format
-- you dont need to do this unless you want to specify what
-- columns you want to insert
⬇️
String = "INSERT INTO Marcas (yourcolumn) VALUES(if your value is string use 'your string' and if is a number you dont use the '')";
-- exemple:
-- because my idcostumer just allows numbers and that is a text one and i use the ''
-- and i dont use the ''
⬇️ ⬇️
ssql = "INSERT INTO Costumer (idcostumer, costumername) VALUES("textboxidcostumer.Text + ", '" + textboxname.Text + "')";