INSERT INTO
The INSERT INTO statement is used to insert a new row in a table.
It is possible to write the INSERT INTO statement in two forms.
The first form doesn't specify the column names where the data will be inserted, only their
values:
INSERT INTO table_name
VALUES (value1, value2, value3,...)
Example:
INSERT INTO CUSTOMER VALUES ('1000', 'Smith', 'John', 12,
'California', '11111111')
The second form specifies both the column names and the values to be inserted:
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)
This form is recommended!
Example:
INSERT INTO CUSTOMER (CustomerNumber, LastName, FirstName, AreaCode,
Address, Phone)
VALUES ('1000', 'Smith', 'John', 12, 'California', '11111111')
Insert Data Only in Specified Columns:
It is also possible to only add data in specific columns.
Example:
INSERT INTO CUSTOMER (CustomerNumber, LastName, FirstName)
VALUES ('1000', 'Smith', 'John')
Note! You need at least to include all columns that cannot be NULL.
i.e., we need to include at least “CustomerNumber”, “LastName” and “FirstName”.
“CustomerId” is set to “identity(1,1)” and therefore values for this column are generated by
the system.
Insert Data in the Designer Tools:
When you have created the tables, you can easily insert data into them using the designer
tools. Right-click on the specific table and select “Edit Top 200 Rows”:
Then you can enter data in a table format, similar to, e.g., MS Excel:
No comments:
Write commentsPlease do not enter spam links