SQL Output
SQL Output
Example:
create table student12(
name char (25),
marks int,
email_id char (25));
Output:
The TRUNCATE
Syntax:
TRUNCATE TABLE <Table_name>
Example
TRUNCATE TABLE student12;
Output
DROP TABLE
Syntax:
DROP TABLE relation_name;
Output:
CONSTRAINTS
NOT NULL
Syntax:
CREATE TABLE Table_Name (column_name data_type (size) NOT
NULL, );
Example:
CREATE TABLE student12(
name char (25) NOT NULL
);
Output:
UNIQUE
Syntax:
CREATE TABLE Table_Name(
column_name data_type(size) UNIQUE, ….);
Example:
CREATE TABLE student11 (name char(25) UNIQUE);
Output:
Example:
CREATE TABLE student101(
name char(25) PRIMARY KEY
);
Output:
INSERT INTO: This is used to add records into a relation. These are
three type of
INSERT INTO queries which are as
UPDATE-SET-WHERE:
Syntax:
SQL>UPDATE relation name SET
Field_name1=data,field_name2=data,
WHERE field_name=data;
SELECT FROM
Output:
Output:
Example of UNION:
ID Name
1 abhi
2 adam
ID Name
2 adam
3 Chester
Syntax:
select * from First
UNION
select * from second
Output:
Union All
ID NAME
1 abhi
2 adam
ID NAME
2 adam
3 Chester
UNION ALL
select * from second
Output:
COMPARISON OPERATORS:
TABLE CODE
supplier_idnumber(10),
supplier_name char(100),
city char(100),
state char(100));
Output:
Output:
LOGICAL OPERATORS:
TABLE CODE:-
CREATE TABLE EMPLOYEE (
emp_id number(20),
emp_name char(20),
Email char(100),
Address char(200));
Output:
AND Operator:
SELECT * FROM EMPLOYEE
WHERE emp_id = 2 AND Address = 'twenth street';
Output:
NOT Operator
Output:
SPECIAL OPERATOR:
BETWEEN
Syntax:
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2
Example:
SELECT EMP_ID
FROM EMPLOYEE
Output:
LIKE Operator:
‘r%’
Output:
Output:
Inner join:
SELECT suppliers1.supplier_id, suppliers1.supplier_name,
orders2.order_date
FROM suppliers1
INNER JOIN orders2
ON suppliers1.supplier_id = orders2.supplier_id;
Output:
Sub query
Syntax:
operandcomparison_operator ANY (subquery)
operand IN (subquery)
operandcomparison_operator SOME (subquery)
Where comparison_operator is one of these operators: = ><>= <= <>
!=
OUTPUT:-
TABLE CODE
CREATE TABLE student (StudentID Varchar(10),Name char(20));
CREATE TABLE marks (StudentID Varchar(10),Total_marks
number(20));
SUBQUERY
SELECT a.studentid, a.name, b.total_marks
FROM student a, marks b
WHERE a.studentid = b.studentid AND b.total_marks >
(SELECT total_marks
FROM marks
WHERE studentid = 'V002');
Output:
Conclusion: Successfully Implemented Nested & Complex Queries
EXPERIMENT NO: 5
CREATE TABLE:
create table Student ( Student_Id int, Name char(20), Marks int, Subject
char(20));
insert into Student values(1,'Ravi',35, 'DBMS');
insert into Student values(2,'Taraka',32,'DSA');
insert into Student values(3,'Priyanka',40, 'DBMS');
AGGREGATION FUNCTIONS
Count.
MIN
Syntax: MIN (Column name)
Example: SELECT MIN(Marks) FROM Student;
Output:
GROUP BY-HAVING:
Syntax:
SELECT column_name, aggregate_function(column_name) FROM
table_name
WHERE column_name operator value
GROUP BY column_name
HAVING aggregate_function(column_name) operator value;
Example:
SELECT COUNT (Marks) FROM Student GROUP BY Marks
HAVING Marks > 10;
Output:
Updating a view
Syntax : CREATE OR REPLACE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition
Output:
Creating Triggers
Syntax:
Example:
Triggering a Trigger
Example:
INSERT INTO CUSTOMERS
(ID,NAME,AGE,ADDRESS,SALARY)
VALUES (7, 'Kriti', 22, 'HP', 7500.00 );
UPDATE customers
SET salary = salary + 500
WHERE id = 2;
Output:-
CREATE VIEW
Output:
DELETE VIEW
DELETE FROM CUSTOMERS_VIEW
WHERE age = 22;
Output: