Search code examples
sqlt-sqlinsert-select

How do you create a row in a table without using the VALUES key word in T-SQL


I got asked an interview question that I haven't a clue how to answer and was curious how you would write a script for something like this.

"Write a statement that creates a row representing you in the Employees table without using the VALUES key word."

How would you create a new row in a table and then add your name to the row without using the VALUES() keyword?

This is the only what that I know how to do something like this but it involves using the VALUES keyword.

INSERT INTO Employees (FirstName, LastName)
VALUES ('John', 'Johnson');

Solution

  • insert into Employees (FirstName, LastName)
    select 'John', 'Johnson'
    

    That way you can easily insert records from other tables or even use joins.