Java Reference
In-Depth Information
For example, the following statement inserts a record into the
Course
table. The new record
has the
courseId
'11113',
subjectId
'CSCI',
courseNumber
'3720',
title
'Database
Systems', and
creditHours
3.
insert into
Course (courseId, subjectId, courseNumber, title, numOfCredits)
values
(
'11113'
,
'CSCI'
,
'3720'
,
'Database Systems'
,
3
);
The column names are optional. If they are omitted, all the column values for the record must
be entered, even though the columns have default values. String values are case sensitive and
enclosed inside single quotation marks in SQL.
The syntax to update a table is:
update
tableName
set
column1 = newValue1
[,
column2 = newValue2, ...
]
[
where
condition];
For example, the following statement changes the
numOfCredits
for the course whose
title
is Database Systems to 4.
update
Course
set
numOfCredits =
4
where
title =
'Database Systems'
;
The syntax to delete records from a table is:
delete from
tableName
[
where
condition];
For example, the following statement deletes the Database Systems course from the
Course
table:
delete from
Course
where
title =
'Database Systems'
;
The following statement deletes all the records from the
Course
table:
delete from
Course;
32.3.5 Simple Queries
To retrieve information from tables, use a
select
statement with the following syntax:
select
column-list
from
table-list
[
where
condition];
The
select
clause lists the columns to be selected. The
from
clause refers to the tables
involved in the query. The optional
where
clause specifies the conditions for the selected
rows.
Query 1:
Select all the students in the CS department, as shown in FigureĀ 32.12.
select
firstName, mi, lastName
from
Student
where
deptId =
'CS'
;
Search WWH ::
Custom Search