Professional Documents
Culture Documents
INDEX
Sr No. Title Date Page No.
10
Experiment No.-1
• Create table
• Alter Table
o Add column
o Drop Column
• Drop table
Theory:
DDL – (DATA DEFINITION LANGUAGE): The SQL sentences that are used to
create these objects are called DDL’s or Data Definition Language. The sql provides various
commands for defining relation schemas, deleting relations, creating indexes and modify relation
schemas. DDL is part of sql which helps a user in defining the data structures into the database.
1. CREATE TABLE: A table is basic unit of storage. It is composed of rows and columns.
To create a table we will name the table and the columns of the table. We follow the rules to
CREATE TABLE tablename (column_name1 datatype (size), column_name2 datatype (size) …);
Example is:
Rollno int,
Name varchar,
Contactno int
);
2. ALTER TABLE: After creating a table one may have need to change the table either by add
new columns or by modify existing columns. One can do so by using alter table command.
Example is:
Example is:
MODIFY(Contactno int);
Example is:
3. DROP TABLE: To remove the definition of oracle table, the drop table statement is used.
Example is:
Output:
EXPERIMENT NO. – 2
AIM: Data Definition Language Commands (DDL) –RENAME Table, CONSTRAINTS on data.
• • RENAME Table
• 1. Primary key
• 2. Not null
THEORY: Structured Query Language (SQL) is the database language, which performs certain
operations on the existing database and also this language is used to create database.
DDL (Data Definition Language): It consists of the SQL commands that can define the database
schema. It deals with descriptions of the database schema and is used to create and modify the
Example:
Screen Shot:
To
CONSTRAINTS:
1. Primary Key:
• Primary Key must contain UNIQUE values, and cannot contain NULL values.
Syntax:
Or
Primary Key(attribute);
Example:
SCREEN SHOT:
2. Not Null:
• The NOT NULL constraint enforces a column to NOT accept NULL values.
Syntax:
Or
Example:
Screen Shot:
Experiment No:3
• Primary Key
• Not Null
• Unique
• Check
• INSERT INTO
• UPDATE
Theory:
Rename Table:- RENAME TABLE is used to change the name of a table. Sometimes,
we choose non-meaningful name for the table. So it is required to be changed.
Example:
Rename Hritik_1902629_1 to Hritik_1902629_2
Output:
To
• Primary Key: A Combination of Unique and not Not Null. Uniquely identifies
each row.
Syntax:
Alter Table Table_Name
ADD Primary Key (Attribute);
Example:
Output:
• Not Null: Ensures that the column cannot have a Null value
Syntax:
Alter table table_name
Modify attribute Not Null;
Example:
Alter table Hritik_1902629_2
Modify Name Not Null;
Alter table Hritik_1902629_2
Modify City Not Null;
Output:
Syntax:
Alter table table_name
Modify attribute Unique;
Example:
Alter table Hritik_1902629_2
Modify Contact Unique;
Output:
• Check: Ensures that the values in the column satisfies a specific condition.
Syntax:
Alter table table_name
Modify attribute check(constraint);
Example:
Alter table Hritik_1902629_2
Modify Age check(Age>16);
Output:
• Update: It is used to modify the existing records in a table. You can use the
WHERE clause with the UPDATE query to update the selected rows, otherwise all
the rows would be affected.
Syntax:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
Example:
Update Hritik_1902629_2
Set City='Jaipur'
where Name='Rajan';
Output:
Experiment No. - 4
Theory:
Example:
DELETE FROM Hritik_1902629 WHERE Rollno= 1902643;
Output:
To
2. SELECT statement : The SELECT statement is used to select data from a database. The
Example:
Insert Into Hritik_1902629 ( Rollno,Name,Contactno, DOB )
Values (1902629, 'Hritik', 123456789,12345);
Insert Into Hritik_1902629 ( Rollno,Name,Contactno, DOB )
Values (1902643, 'krish', 1236789,00000);
OUTPUT:
Example:
SELECT DISTINCT Name
From Hritik_1902629;
OUTPUT:
Practical No.-5
Aim: SQL using- where; OR, AND and OR operators
Objectives: To Study and Execute SELECT Statement using:
1. WHERE Clause
2. Where with “AND, OR, NOT”
3. Where with Relational Operator (<,>,<=,>=,<>)
Theory:
1) WHERE Clause:
Screenshot:
Syntax:-
SELECT column1, column2, ...
FROM table_name
WHERE condition1 AND condition2 AND condition3 ...;
Example:
Select Roll_No,name,marks from hritik_1902629_5
Where Marks<=50 And City='Delhi';
Screenshot:
Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition1 ORcondition2 AND condition3 ...;
Example:-
Select Roll_No,name,marks from hritik_1902629_5
Where Marks<=50 OR City='Delhi';
Screenshot:
Syntax
SELECT column1, column2, ...
FROM table_name
WHERE NOT condition;
Screenshot:
Syntax:-
SELECT[column_name| * value1>value2;
Example:-
Select Roll_No,Name from hritik_1902629_5
Where Marks>50;
Screenshot:
Syntax:-
SELECT[column_name| * value1<value2;
Example:-
Select Roll_No,Name from hritik_1902629_5
Where Marks<50;
Screenshot:
Greater than and equal to(>=):It checks whether the left operand is greater than and equal
to or not.
Syntax:-
SELECT[column_name| * value1>=value2;
Example:-
Select Roll_No,Name from hritik_1902629_5
Where Marks>=50;
Screenshot:
lessthan(<=):It checks whether the right operand is greater and equal to or not.
Syntax:-
SELECT[column_name| * value1<=value2;
Example:-
Select Roll_No,Name from hritik_1902629_5
Where Marks<=50;
Screenshot:
Equal to(=):-It checks whether the both values are equal or not.
Syntax:-
SELECT[column_name| * value1=value2;
Example:-
Select Roll_No,Name from hritik_1902629_5
Where Marks=50;
Screenshot:
Not Equal to(<>):-It prints the values which are not equal.
Syntax:-
SELECT[column_name| * value1<>value2;
Example:-
Select Roll_No,Name from hritik_1902629_5
Where Marks<>50;
Screenshot: