Introduction
Inserting data
3. Insert data
Modifying data
Deleting data
CRUD

Instruction

All right, we'll start off with inserting data into our database. To add data to a table, you use the INSERT command. Let's add a 9-year-old Alice as a user with an ID of 5:

INSERT INTO User 
VALUES (5, N'Alice', 9); 

See what happened? After INSERT INTO, we put the name of the table (User) that we're adding information to. Next, we add the keyword VALUES followed by the actual values (5, N'Alice', 9) for each column of the table. As you can see, the values must be surrounded by parentheses and are separated with commas.

The first number is the value for the Id column. The Id column is a numeric column, so we just type the number.

The text N'Alice' is the value for the second column, Name. It is a text column, meaning it contains short text information. In SQL Server, you surround text information with single quotes ('example'). If your database can contain non-ASCII text values (as is the case in our example database), you prefix text information with N (N'example').

The number 9 is the value for the third column, Age. It is a numeric column, just like Id, so we just type the number.

Remember, in this case, you need to put the values in the exactly same order in which the columns appear in the database.

Exercise

The restaurant owners decided to introduce some Balkan cuisine, so we need to refresh the menu a little bit.

Add a dish called Cevapcici with an ID of 9 and a Price of 27. It's a main course.

Stuck? Here's a hint!

Type:

INSERT INTO Dish 
VALUES (9, N'main course', N'Cevapcici', 27);