Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

1

© BELGIUM CAMPUS 2021


2

© BELGIUM CAMPUS 2021


3

When using the INSERT statement, keep the following in mind.

Adding data of the Insert into one base table Violate a rule or constraint, CHAR columns are right-
incorrect datatype at a time the INSERT fails padded

© BELGIUM CAMPUS 2021


4

INSERT INTO TableName

(ColumnName1, ColumnName2, ColumnName3, ColumnName4)

VALUES

(Value1, Value2, Value3, Value4)


5

There must be a match between the number of columns defined and the number of
values supplied. The order of the columns and values must also match.

INSERT INTO Employee


Numeric datatypes will not be
(FirstName, LastName, Age, DateHired) placed within quotes, this does
not apply to dates. Also, all
columns that have a NOT NULL
defined must be added in the
VALUES INSERT, this does not apply to a
PRIMARY KEY that has an IDENTITY
( ‘Jane’ , ‘Smith’ , 43 , ‘2018/02/04’) specified, as the IDENTITY
generates its own value.
6

Very similar to the append query you have in Access, SQL also allows you to SELECT data
from one table and INSERT it into another table.

INSERT INTO TableName

SELECT EmployeeID, FirstName, LastName, Age, DateHired, Status

This will give us the


data we want to insert. FROM Employees

WHERE Status = ‘Fired’


7

The UPDATE statement has a few restrictions that are very similar to those of the INSERT statement.

Changing values to violate Updating one base table CHAR columns are right-
datatype, NULL options or at a time padded
constraints.

© BELGIUM CAMPUS 2021


8

UPDATE TableName

SET Column1 = Value1, ,

Column2 = Value2,

WHERE Criteria
9

UPDATE Employees
If no WHERE clause is
specified, all the rows in the
table will be updated to the
SET Status = ‘Fired’ new value. This could lead to
devastating effects in a
system. All criteria that are
valid in a SELECT statement
WHERE FirstName = ‘Linda’ AND LastName = ‘Jones’ are valid for use in the WHERE
clause of the UPDATE.
10

DELETE FROM TableName TRUNCATE TABLE Employees

WHERE Criteria
11

Please complete the Select and


Indexing Exercises 1 through 4. You
will have 20 minutes.

© BELGIUM CAMPUS 2021

You might also like