0% found this document useful (0 votes)
8 views6 pages

P17

The document details the creation and manipulation of two tables, StudentDetails and StudentMarks, in an SQL database, including the insertion of student records. It also describes the creation of views to display specific data, an index on the StudentDetails table, and a sequence for generating unique identifiers. The operations demonstrate basic SQL commands for managing and querying database tables.

Uploaded by

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

P17

The document details the creation and manipulation of two tables, StudentDetails and StudentMarks, in an SQL database, including the insertion of student records. It also describes the creation of views to display specific data, an index on the StudentDetails table, and a sequence for generating unique identifiers. The operations demonstrate basic SQL commands for managing and querying database tables.

Uploaded by

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

SQL*Plus: Release 10.2.0.1.

0 - Production on Fri Sep 13 11:59:46 2024

Copyright (c) 1982, 2005, Oracle. All rights reserved.

SQL> connect system


Enter password:
Connected.
SQL> CREATE TABLE StudentDetails (
2 S_ID INT PRIMARY KEY,
3 NAME VARCHAR(255),
4 ADDRESS VARCHAR(255)
5 );

Table created.

SQL> INSERT INTO StudentDetails (S_ID, NAME, ADDRESS)


2 VALUES(1, 'Harsh', 'Kolkata');

1 row created.

SQL> INSERT INTO StudentDetails (S_ID, NAME, ADDRESS)


2 VALUES(2, 'Ashish', 'Durgapur');

1 row created.

SQL> INSERT INTO StudentDetails (S_ID, NAME, ADDRESS)


2 VALUES(3, 'Pratik', 'Delhi');

1 row created.

SQL> INSERT INTO StudentDetails (S_ID, NAME, ADDRESS)


2 VALUES(4, 'Dhanraj', 'Bihar');

1 row created.

SQL> INSERT INTO StudentDetails (S_ID, NAME, ADDRESS)


2 VALUES(5, 'Ram', 'Rajasthan');

1 row created.

SQL> SELECT * FROM StudentDetails;

S_ID
----------
NAME
--------------------------------------------------------------------------------
ADDRESS
--------------------------------------------------------------------------------
1
Harsh
Kolkata
2
Ashish
Durgapur

S_ID
----------
NAME
--------------------------------------------------------------------------------
ADDRESS
--------------------------------------------------------------------------------

3
Pratik
Delhi

4
Dhanraj

S_ID
----------
NAME
--------------------------------------------------------------------------------
ADDRESS
--------------------------------------------------------------------------------
Bihar

5
Ram
Rajasthan

SQL> CREATE TABLE StudentMarks (


2 ID INT PRIMARY KEY,
3 NAME VARCHAR(255),
4 Marks INT,
5 Age INT
6 );

Table created.

SQL> INSERT INTO StudentMarks (ID, NAME, Marks, Age)


2 VALUES
3 (1, 'Harsh', 90, 19),
4
SQL> INSERT INTO StudentMarks (ID, NAME, Marks, Age)
2 VALUES(1, 'Harsh', 90, 19);

1 row created.

SQL> INSERT INTO StudentMarks (ID, NAME, Marks, Age)


2 VALUES(2, 'Suresh', 50, 20);
1 row created.

SQL> INSERT INTO StudentMarks (ID, NAME, Marks, Age)


2 VALUES(3, 'Pratik', 80, 19);

1 row created.

SQL> INSERT INTO StudentMarks (ID, NAME, Marks, Age)


2 VALUES(4, 'Dhanraj', 95, 21);

1 row created.

SQL> INSERT INTO StudentMarks (ID, NAME, Marks, Age)


2 VALUES(5, 'Ram', 85, 18);

1 row created.

SQL> SELECT * FROM StudentMarks;

ID
----------
NAME
--------------------------------------------------------------------------------
MARKS AGE
---------- ----------
1
Harsh
90 19

2
Suresh
50 20

ID
----------
NAME
--------------------------------------------------------------------------------
MARKS AGE
---------- ----------

3
Pratik
80 19

4
Dhanraj

ID
----------
NAME
--------------------------------------------------------------------------------
MARKS AGE
---------- ----------
95 21

5
Ram
85 18

SQL> CREATE VIEW StudentNames AS


2 SELECT S_ID, NAME
3 FROM StudentDetails
4 ORDER BY NAME;

View created.

SQL> SELECT * FROM StudentNames;

S_ID
----------
NAME
--------------------------------------------------------------------------------
2
Ashish

4
Dhanraj

1
Harsh

S_ID
----------
NAME
--------------------------------------------------------------------------------
3
Pratik

5
Ram

SQL> CREATE VIEW DetailsView AS


2 SELECT NAME, ADDRESS
3 FROM StudentDetails
4 WHERE S_ID < 5;

View created.

SQL> SELECT * FROM DetailsView;

NAME
--------------------------------------------------------------------------------
ADDRESS
--------------------------------------------------------------------------------
Harsh
Kolkata

Ashish
Durgapur

Pratik
Delhi

NAME
--------------------------------------------------------------------------------
ADDRESS
--------------------------------------------------------------------------------
Dhanraj
Bihar

SQL> CREATE VIEW MarksView AS


2 SELECT StudentDetails.NAME, StudentDetails.ADDRESS, StudentMarks.MARKS
3 FROM StudentDetails, StudentMarks
4 WHERE StudentDetails.NAME = StudentMarks.NAME;

View created.

SQL> SELECT * FROM MarksView;

NAME
--------------------------------------------------------------------------------
ADDRESS
--------------------------------------------------------------------------------
MARKS
----------
Harsh
Kolkata
90

Pratik
Delhi
80

NAME
--------------------------------------------------------------------------------
ADDRESS
--------------------------------------------------------------------------------
MARKS
----------

Dhanraj
Bihar
95
Ram
Rajasthan

NAME
--------------------------------------------------------------------------------
ADDRESS
--------------------------------------------------------------------------------
MARKS
----------
85

SQL> CREATE INDEX idx


2 ON StudentDetails(NAME);

Index created.

SQL> CREATE SEQUENCE seq_person


2 MINVALUE 1
3 START WITH 1
4 INCREMENT BY 1
5 CACHE 10;

Sequence created.

SQL>

You might also like