Data Manipulation Using SQL - Lec3
Data Manipulation Using SQL - Lec3
SQL
There are 3 basic categories of SQL
Statements
• SQL-Data Statements -- query and modify
tables and columns
– SELECT Statement -- query tables and views in the
database.
– INSERT Statement -- add rows to tables.
– UPDATE Statement -- modify columns in table
rows.
– DELETE Statement -- remove rows from tables.
There are 3 basic categories of SQL
Statements
• SQL-Schema Statements -- maintain schema
(catalog)
– CREATE TABLE Statement -- create tables .
– CREATE VIEW Statement -- create views .
– DROP TABLE Statement -- drop tables .
– DROP VIEW Statement -- drop views .
Not Equal
SELECT * FROM Customers WHERE LastName <> 'Smith‘
Greater than
SELECT * FROM Customers WHERE DOB > '1/1/1970'
Greater or Equal
SELECT * FROM Customers WHERE DOB >= '1/1/1970‘
Less than
SELECT * FROM Customers WHERE DOB < '1/1/1970‘
Less or Equal
SELECT * FROM Customers WHERE DOB <= '1/1/1970‘
Similar to
SELECT * FROM Customers WHERE Phone LIKE '626%‘
Defines a range
SELECT * FROM Customers WHERE DOB BETWEEN '1/1/1970' AND '1/1/1975'
SQL INSERT INTO
• The SQL INSERT INTO syntax has 2 main forms
and the result of either of them is adding a
new row into the database table.
SQL INSERT INTO
• The first syntax form of the INSERT INTO SQL
clause doesn't specify the column names
where the data will be inserted, but just their
values:
• NOT NULL -- specifies that the column can't be set to null. If this constraint is not
specified, the column is nullable, that is, it can be set to null. Normally, primary key
columns are declared as NOT NULL.
• PRIMARY KEY -- specifies that this column is the only column in the primary key.
There can be only one primary key declaration in a CREATE TABLE. For primary keys
with multiple columns, use the PRIMARY KEY table constraint. See Entity Integrity
below for a detailed description of primary keys.
• UNIQUE -- specifies that this column has a unique value or null for all rows of the
table.
• REFERENCES -- specifies that this column is the only column in a foreign key. For
foreign keys with multiple columns, use the FOREIGN KEY table constraint. See
Referential Integrity below for a detailed description of primary keys.
The Table Constraints
• PRIMARY KEY -- specifies the set of columns that comprise the
primary key. There can be only one primary key declaration in a
CREATE TABLE Statement.