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

1.

Create a table
We start by creating an empty table by firing the following query
CREATE TABLE AMTC.STUDENT ( STUDNO INTEGER, FNAME VARCHAR2(25), LNAME
VARCHAR2(25), AGE INTEGER, EMAIL VARCHAR2(50))

2.Inserting records in a table


Inserting data in a table is very easy. Just type the following query
INSERT INTO AMTC.STUDENT ( STUDNO, FNAME, LNAME, AGE, EMAIL) VALUES (
1, EUGEN, MORAR, 32, eugen28@yahoo.com);

3.Viewing all records from a table.


It is simplest of all & most frequently used query. Just type
SELECT * FROM AMTC.STUDENT
SELECT * FROM AMTC.STUDENT ORDER BY AGE;

4.Viewing only selected records from a table


If there are a huge number of rows in a table and we do not want all the records to
fill our display screen, then SQL gives us an option to view only selected rows.
SELECT COUNT(1) FROM AMTC.STUDENT;
SELECT COUNT * FROM AMTC.STUDENT;
SELECT STUDNO, (FNAME || - || LNAME) as NAME, AGE FROM
AMTC.STUDENT;
SELECT MAX(AGE) FROM AMTC.STUDENT;
SELECT MIN(AGE) FROM AMTC.STUDENT;
SELECT SUM(AGE) FROM AMTC.STUDENT;

5.Deleting records from a table


To delete the selected rows from a table, just fire the following query:
DELETE FROM AMTC.STUDENT WHERE FNAME = EUGEN;

6.Changing data in existing records in a table


Suppose we want to change the age of a student named Eugen in our table. We
would fire this query:
UPDATE AMTC.STUDENT SET AGE = 22 WHERE LNAME = EUGEN;

7.Viewing records from a table without knowing exact details

In real life, when we interact with database, there are major chances that we do not
know any of the column values exactly.
SELECT * FROM AMTC.STUDENT WHERE FNAME LIKE E%;

8.Using more than one condition in WHERE clause to retrieve records


To understand the requirement of using this parameter, let us first insert one more
row in our table.
SELECT * FROM AMTC.STUDENT WHERE FNAME =DAN;
SELECT * FROM AMTC.STUDENT WHERE FNAME =DAN AND AGE = 24;
SELECT * FROM AMTC.STUDENT WHERE FNAME =DAN OR AGE > 25;

9.Viewing only selected columns from a table


If we fire a query like
SELECT LNAME FROM AMTC.STUDENT WHERE AGE > 25;
SELECT LNAME, AGE FROM AMTC.STUDENT;
SELECT AGE, LNAME FROM AMTC.STUDENT;

10.Know the structure of table


It happens with me quite many times that I create a table in my database and I forget
what all columns it has and which column is primary key.
DESCRIBE AMTC.STUDENT;

You might also like