카테고리 없음

SQL INSERT INTO Statement

AKA.DM 2022. 4. 20. 13:03
반응형

The SQL INSERT INTO Statement

 

The INSERT INTO statements is used to insert new reocrds in a table

 

Two ways to use INSERT INTO statement

 

1. Specify both the column names and the values to be inserted.

INSERT INTO table_name (Column1, column2, ....)

VALUES (value1, value2...) ;

 

2. If wants to add the values for all the columns of the table, make sure the order of the values is in the same order as the column in the table. 

INSERT INTO table_name

VALUES (value1, value2...);

 

the sample database goes like below

 

If add the new row as CustomerID 92, it will goes to lie this

INSERT INTO Customers(CustomerName, ContactName, Address, City, PostalCode, Country)

VALUES ('seong', 'hugh', 'bongeunsaro644', 'seoul', '06830', 'S.Korea');

 

and the Customers Table goes like this

as result, the new row added in the database 

 

In this case, if want to add the new row as CustomerID 90, it will be shown error.

 

How to insert data only in specifed columns?

 

the SQL statements will be like below

 

INSERT INTO Customers (CustomerName, City)

VALUES ('hahah', 'Seoul');

if the vlaues are not specified, it shows null instead of blank

반응형