W3. SQL Insert Into Flashcards
Q: What is the purpose of the SQL INSERT INTO statement?
A: To insert new records into a table.
Q: What is one way to write the INSERT INTO statement with specified columns?
INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);
Q: How do you insert values into all columns without specifying column names?
INSERT INTO table_name VALUES (value1, value2, value3, ...);
(Ensure values are in the correct order.)
Q: Write an example INSERT INTO statement that adds a record with specific column names in the “Customers” table.
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country) VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');
Q: What happens to an AUTO_INCREMENT column like CustomerID when a new record is inserted?
A: It is generated automatically without specifying a value for it.
Q: Can you insert data into specific columns only? Provide an example.
A: Yes, by specifying only those columns.
INSERT INTO Customers (CustomerName, City, Country) VALUES ('Cardinal', 'Stavanger', 'Norway');
Q: How do you insert multiple rows in a single INSERT INTO statement?
A: Use multiple sets of values, separated by commas.
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country) VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway'), ('Greasy Burger', 'Per Olsen', 'Gateveien 15', 'Sandnes', '4306', 'Norway');
Q: What must you do to separate multiple rows in a single INSERT INTO statement?
A: Separate each row of values with a comma.