ex 1,2 (1)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

SQL AND INTERNET SECURITY LAB

1. Creating , Modifying and Dropping tables


Creating Table
SQL> create table Student1(RegNo varchar2(8), Name varchar2(30),
Dept varchar2(15), Year varchar2(6));

Table created.
Finding the column details of a table created
SQL> desc Student1
Name Null? Type
------------------------------- -------- ----
REGNO VARCHAR2(8)
NAME VARCHAR2(30)
DEPT VARCHAR2(15)
YEAR VARCHAR2(6)

Modifying the Structure of table


SQL> Alter table student1 Add (Mark number(6,2));

Table altered.
SQL> desc student1
Name Null? Type
------------------------------- -------- ------------------
REGNO VARCHAR2(8)
NAME VARCHAR2(30)
DEPT VARCHAR2(15)
YEAR VARCHAR2(6)
MARK NUMBER(6,2)
SQL> Alter table Student1 Modify ( RegNo varchar2(10) );
Table altered.
SQL> desc student1
Name Null? Type
------------------------------- -------- ----
REGNO VARCHAR2(10)
NAME VARCHAR2(30)
DEPT VARCHAR2(15)
YEAR VARCHAR2(6)
MARK NUMBER(6,2)

Destroying Table
SQL> drop table student1 ;
SQL> desc student1
ERROR:
ORA-04043: object student1 does not exist
2. Inserting, Modifying and Deleting rows

SQL> desc student1


Name Null? Type
------------------------------- -------- ----
REGNO VARCHAR2(10)
NAME VARCHAR2(30)
DEPT VARCHAR2(15)
YEAR VARCHAR2(6)
MARK NUMBER(6,2)

Insertion of data into table

SQL> insert into student1 ( regno, name, dept, year ) values ('18ACS65', 'Amar',
'Computer','Third');
1 row created.

SQL> insert into student1 ( regno, name, dept, year ) values('18AMA75', 'Akbar',
'Mathematics', 'Third' );
1 row created.

SQL> insert into student1 values('19ACS80', 'Antony', 'Computer', 'Second' ,78.48);


1 row created.

SQL> insert into student1 values('18ACS78', 'Akbar', 'Computer', 'Third',98.45);


1 row created.

Viewing data in the table ( All rows and All columns )

SQL> select * from student1;

REGNO NAME DEPT YEAR MARK


---------- ------------------------------ --------------- ------ ---------
18ACS65 Amar Computer Third
18AMA75 Akbar Mathematics Third
19ACS80 Antony Computer Second 78.48
18ACS78 Akbar Computer Third 98.45

Viewing data in the table ( All rows and Selected columns )

SQL> select RegNo, Name from Student1;


REGNO NAME
---------- ---------------------------
18ACS65 Amar
18AMA75 Akbar
19ACS80 Antony
18ACS78 Akbar

Updating / Modifying the contents of a table

SQL> update student1 set mark = 75.35 where regno = '18AMA75';


1 row updated.

SQL> select * from student1;

REGNO NAME DEPT YEAR MARK


---------- ------------------------------ --------------- ------ ---------
18ACS65 Amar Computer Third
18AMA75 Akbar Mathematics Third 75.35
19ACS80 Antony Computer Second 78.48
18ACS78 Akbar Computer Third 98.45

SQL> update student1 set mark = mark + 1.5;


4 rows updated.

SQL> select * from student1;

REGNO NAME DEPT YEAR MARK


---------- ------------------------------ --------------- ------ ---------
18ACS65 Amar Computer Third
18AMA75 Akbar Mathematics Third 76.85
19ACS80 Antony Computer Second 79.98
18ACS78 Akbar Computer Third 99.95

Removal of selected rows

SQL> delete from student1 where dept != 'Computer';


1 row deleted.

SQL> select * from student1;

REGNO NAME DEPT YEAR MARK


---------- ---------------------------- --------------- ------ ---------
18ACS65 Amar Computer Third
19ACS80 Antony Computer Second 79.98
18ACS78 Akbar Computer Third 99.95

Removal of All rows

SQL> delete from student1;

3 rows deleted.

SQL> select * from student1;

no rows selected

You might also like