SQL Commands and Outputs
SQL Commands and Outputs
Experiment: Write & execute DDL & DML commands with example.
Commands:
-- DDL Example
Name VARCHAR(100),
Salary DECIMAL(10, 2)
);
-- DML Example
INSERT INTO Employees (ID, Name, Salary) VALUES (1, 'John Doe', 50000);
Output:
ID | Name | Salary
---|----------|-------
Commands:
-- DCL Example
-- TCL Example
BEGIN TRANSACTION;
INSERT INTO Employees (ID, Name, Salary) VALUES (2, 'Jane Smith', 60000);
COMMIT;
Output:
ID | Name | Salary
---|------------|-------
Commands:
WHERE ID NOT IN (
SELECT MIN(ID)
FROM Employees
);
Output:
ID | Name | Salary
---|------------|-------
Commands:
SELECT * FROM (
FROM Employees
) AS TempTable
WHERE RowNum % 2 = 1;
WHERE ID IN (
SELECT ID FROM (
FROM Employees
) AS TempTable
WHERE RowNum % 2 = 0
);
Output:
ID | Name
---|------------
1 | John Doe
3 | Alice Brown
Experiment: Write a query to find third highest & third lowest paid salary.
Commands:
FROM Employees
) AS RankedSalaries
WHERE Rank = 3;
FROM Employees
) AS RankedSalaries
WHERE Rank = 3;
Output:
Commands:
WHERE Name LIKE 'J%' OR Name LIKE 'K%' OR Name LIKE 'L%' OR Name LIKE 'M%';
Output:
Name
----------
John Doe
Jane Smith
Experiment: Display three records in the first row & two records in the second row & one record in the third row in a
Commands:
UNION ALL
UNION ALL
Output:
Name
----------
John Doe
Jane Smith
Alice Brown
(and so on...)
Experiment: Write a PL/SQL statement for select, insert, update & delete statements.
Commands:
DECLARE
emp_name VARCHAR(100);
BEGIN
-- Select statement
-- Insert statement
INSERT INTO Employees (ID, Name, Salary) VALUES (3, 'Alice Brown', 70000);
-- Update statement
-- Delete statement
END;
Output:
Commands:
DECLARE
emp_name Employees.Name%TYPE;
hire_date Employees.HireDate%TYPE;
BEGIN
OPEN emp_cursor;
LOOP
END LOOP;
CLOSE emp_cursor;
END;
Output:
Commands:
BEGIN
END IF;
END;
Output:
Commands:
-- ER Diagram Concept
-- An ER diagram for a Student Record System typically includes entities such as Students, Courses, Enrollments,
Instructors, etc.
-- Each entity has attributes, and relationships are shown between entities.
Output:
Commands:
Name VARCHAR(100)
);
StudentID INT,
CourseID INT,
);
Output: