0% found this document useful (0 votes)
37 views11 pages

Introduction To SQL - 2: Saturday 22,2001

This document discusses various SQL statements like INSERT, UPDATE, DELETE, CREATE, ALTER, and DROP. It provides the syntax and usage of each statement. The last section assigns students to write queries to generate reports from tables in Annexure B and attach the output. The reports required are on order details by customer, product sales details, total sales by customer, and total sales by product.

Uploaded by

Waseem Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views11 pages

Introduction To SQL - 2: Saturday 22,2001

This document discusses various SQL statements like INSERT, UPDATE, DELETE, CREATE, ALTER, and DROP. It provides the syntax and usage of each statement. The last section assigns students to write queries to generate reports from tables in Annexure B and attach the output. The reports required are on order details by customer, product sales details, total sales by customer, and total sales by product.

Uploaded by

Waseem Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 11

Lecture 8

Introduction to SQL - 2

Saturday 22,2001
INSERT Statement
 Syntax

INSERT INTO table [( column[, column..])]


{VALUES (value [, value….]) | subquery}

– have two main clauses


• insert
• values

– adds only one row at a time


INSERT Statement
 INSERT clause
– used to specify the name of table to which row will be
inserted and optionally the name of columns to which values
will be inserted
– if table name is mentioned only then values will be inserted
in all the columns in that table implicitly
– if column names are mentioned explicitly then values will be
inserted in these columns only
INSERT Statement
 VALUES clause
– used to specify the values for columns mentioned in
insert clause
– number and type of values in values clause must match
with the columns mentioned in insert clause
– you can provide NULL as value for some column if you
have no value for that column
values (3456,’martin’,null)
– a select statement can be used in place of values clause
for providing input values
– rule 2 is also applicable in case of subqueries
UPDATE Statement
 Syntax

UPDATE table
SET column = value [, column = value , ….]
[WHERE condition];

– have three main clauses


• update
• set
• where

– can change more than one row at a time


– where clause is same as select statement and used to
specify the rows to be updated
UPDATE Statement
 UPDATE clause
– used to specify the name of table

 SET clause
– used to specify the name of columns where values to be
changed and new values for those columns
– another form of set clause is:
SET ( column, column,..) = ( subquery )
– in this case number of columns mentioned on left side must
equal to the number of columns returned by subquery
– if where clause is omitted all rows will be updated
DELETE Statement
 Syntax

DELETE [ FROM ] table


[WHERE condition];

– have two main clauses


• delete
• where
– delete clause specifies the table from where rows to be
deleted
– where clause is same as select statement and used to
specify the rows to be deleted
– if where clause is omitted all rows in the table will be
deleted
CREATE Statement
 Syntax

CREATE TABLE table


{( column datatype [ DEFAULT expr ] [,...]) | AS subquery };

– table is name of table to create


– column is name of a column in that table
– datatype is data type of that column and size
– DEFAULT specifies the default value for that column
– a subquery can be used to provide data to the table at the
time of creation
– if there is any computed column in subquery than provide an
alias for that column
ALTER Statement
 Syntax

ALTER TABLE table


{ ADD ( column datatype [ DEFAULT expr ] [,...]) |
MODIFY ( column datatype [ DEFAULT expr ] [,...]) };

– table is name of table to alter


– column is name of a column in that table
– datatype is data type of that column and size
– ADD is used to add new column in the table
– MODIFY is used to change the existing column in the table
DROP Statement
 Syntax

DROP TABLE table ;

– table is name of table to drop


– all data and structure in the table is deleted
– all indexes are dropped
Assignment # 3
 Refer to Annexure B of Introduction to SQL and PL/SQL
(pages 281 to 291)
 write queries for following purposes and also attach the output
of that query. Output should be ordered properly
– we want to prepare a report showing details of orders associated to
each customer. Required columns in report are custid,
ordid,prodid,actualprice,qty,itemtot.
– we want to prepare a report showing details of sales of different
products. Required columns in report are prodid,ordid,custid,
actualprice,qty,itemtot.
– A report showing total sales for each customer. Required columns
are custid and total, where total is the sum of amounts spent by that
customer on the purchase of different products through different
orders.
– A report showing total sales for each product. Required columns
are prodid and total, where total is the sum of amounts earned
through sales of that product through different orders.

 Due Date: 05/10/2001

You might also like