0% found this document useful (0 votes)
10 views8 pages

SQL Commands - 2025

The document provides a comprehensive overview of SQL concepts, including data types, commands, and functions. It covers differences between char and varchar, DELETE vs. DROP commands, and various SQL operators and functions. Additionally, it includes syntax and examples for creating, updating, and deleting records in SQL tables.

Uploaded by

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

SQL Commands - 2025

The document provides a comprehensive overview of SQL concepts, including data types, commands, and functions. It covers differences between char and varchar, DELETE vs. DROP commands, and various SQL operators and functions. Additionally, it includes syntax and examples for creating, updating, and deleting records in SQL tables.

Uploaded by

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

2-MARKS QUESTIONS

1. Give the difference between char and varchar data types in SQL.

Char Varchar
It stores fixed length characters It stores variable length characters
Maximum size is 2000 bytes or characters Maximum size is 4000 bytes or characters
Default and Minimum size is 1 1 byte or character Default and Minimum size is 1 byte or character
Syntax : char(size) Syntax : varchar(size)

2. Compare DELETE and DROP command in SQL.

Delete Drop
It is used to delete the records in a table It is used to delete the structure of the table
Syntax : delete from tablename where <condition>; Syntax : drop table tablename;
Ex: delete from ebill where name=’aaa’; Ex : drop table ebill;

3. Write the purpose of MAX() and MIN() group functions in SQL.


MAX() MIN()
It is used to get the maximum value from a column It is used to get the minimum value from a column
Ex: select max(sal) from employee; select min(sal) from employee;

4. Explain any two arithmetic operators in SQL

Ans) Arithmetic operators(+,-,*,/,%)

Operators Description Example


assume a=10 ,b=5
+ Addition - Adds two values a + b will give 15
- Subtraction - Subtracts one value from another. a - b will give 5
* Multiplication – Multiplies two values. a * b will give 50
/ Division - Divides one value by another a / b will give 2

5. Explain any two logical operator in SQL

ANS)

Operators Description Example


assume a=10 ,b=5
AND Returns TRUE if both conditions are true. Select * from student where name= ‘A’ and perc=60;
OR Returns TRUE if at least one condition is true. Select * from student where name= ‘A’ or perc=60;
NOT Reverses the condition , it is a negate operator Select * from student where not perc=60;

6. Write the syntax and example of INSERT command in SQL


ANS) The insert statement is used to insert a record into a table
Syntax :
INSERT INTO tablename VALUES(value1.value2…valueN);
Example:
INSERT INTO student VALUES(01,’aaa’,50,51,53);
7. Give the syntax and example for DELETE command in SQL.
ANS) It is used to delete the records in a table
Syntax :
Syntax : DELETE FROM tablename WHERE <condition>;
Example:
DELETE FROM ebill WHERE name=’aaa’;

8. Give the syntax and example of UPDATE command in SQL


ANS) The update statement is used to update existing records in a table
Syntax :
UPDATE <tablename> SET <column_name> = <value> WHERE <condition>
Example :
UPDATE student SET total=99 WHERE regno=10;

9. Write the syntax and example for DROP command in SQL


Ans) It is used to delete the structure of the table
Syntax :
DROP TABLE tablename;
Example :
DROP TABLE ebill;

10. Explain any two relational/Comparison operators in SQL with suitable examples
Operators Description Example
assume a=10 ,b=5
= Checks if values are equal. SELECT * FROM students WHERE age = 18;
!= Checks if values are NOT equal. SELECT * FROM students WHERE grade != 'A';
> Checks if one value is greater than another. SELECT * FROM students WHERE age > 18;
< Checks if one value is smaller than another. SELECT * FROM students WHERE age < 18;

11. Discuss any 2 character (text) built-in functions in SQL.

Function Description Example


LOWER It converts all letters to lower case LOWER(‘HELLO’) // hello
UPPER It converts all letters to upper case UPPER(‘hello’) // HELLO
LENGTH It returns the length of characters Length(‘hello’)// 5

12. What is the difference between ORDER BY and GROUP BY clause used in SQL? Give example
for each.
ORDER BY GROUP BY
It is used to sort the data in ascending or It is used with group function to retrieve data grouped
descending order according to one or more column
Syntax : SELECT <columns> FROM table WHERE Syntax: SELECT <columns> FROM table WHERE
<conditions> ORDER BY <column> ASC/DESC; <conditions> GROUP BY <columns>
Ex: SELECT * FROM students ORDER BY age ASC; Ex: SELECT city, COUNT(*) FROM students GROUP BY city;
13. Give the syntax and example of Create command in SQL.
It is used to create table
Syntax : CREATE TABLE <tablename> (column1 datatype(size), column2 datatype(size)…column
datatype(size));
Ex: Create table student(SID varchar2(10), SNAME , varchar2(15),per number(5));

14. Give the syntax and example of alter command in SQL.


It is used to modify an existing table such as a by adding, deleting, or modifying columns
Syntax : ALTER TABLE table_name
ADD | DROP | MODIFY column_name data_type;
Ex: ALTER TABLE student ADD (result varchar2(15));

15. Give the syntax and example of truncate command in SQL.


It is used to delete all records from table without affecting table structure
Syntax : TRUNCATE statement;

16. What is DML ? Mention different DML statement


Data Manipulation Language is used to modify data in a database and includes INSERT, UPDATE,
DELETE, and SELECT statements.
17. What is DDL? Mention different DDL statement
Data Definition Language is used to define and manage database structures, including CREATE,
ALTER, DROP, and TRUNCATE.
18. What is TCL ?Mention different TCL statement
Transaction Control Language manages database transactions using COMMIT, ROLLBACK, and
SAVEPOINT

19. Explain various group functions in SQL

Functions Example
Min() - It is used to get the minimum value from a column SELECT MIN(salary) FROM employee;
Max() - It is used to get the maximum value from a column SELECT MAX(salary) FROM employee;
Sum() – it is used to get sum of all values present in column SELECT SUM(salary) FROM employee;
Avg() - it is used to get average value present in column SELECT AVG(salary) FROM employee;
Count()- it is used to count number of rows in table SELECT COUNT(*) FROM employee;

20. Explain various group functions in SQL


Char : It stores fixed length characters, Syntax : CHAR(size)
varchar2: It stores variable length characters, Syntax : VARCHAR2(size)
Number: it is used to store numberic values Syntax: NUMBER(precision,[scale])
Precision – it describes maximum number of digits that can be used
Scale –it represents number of digits after decimal point
EX: number(10,2) // 1200.45
date: it is used to store date – default format – DD-MON-YY
5 MARKS QUESTIONS

ANS) Create Table:


create table employee ( Empid number(10), Name varchar2(20), Age number(10),
Salary number(10));

Display Structure:
desc employee;

Find Total Number of Employees:


select count(*) as TotalEmployees from Employee;

Find Sum of All Salaries:


select sum(Salary) as TotalSalary from Employee;

Display Employees with Age >= 15:


select * from Employee where Age >= 15;

ANS)

Create Table:
create table Student (Regno number(10), Name varchar2(20),DOB date, Marks number(10));

Find Total Number of Students:


select count(*) AS TotalStudents from Student;
Find Highest Marks:
select max(Marks) as HighestMarks from Student;

Find Lowest Marks:


select min(Marks) as LowestMarks from Student;

Display All Student Records:


select * from student;

Display All Records


select * from employee;

Find Maximum Net Salary:


select max(Net_Salary) as MaxNetSalary from Employee;

Find Minimum Net Salary:


select min(Net_Salary) as MinNetSalary from Employee;

Delete All Records:


delete from Employee;

Remove the Table:


drop table Employee;
Create Table:
create table student (regno number(10), name varchar2(20), marks number(10));

Insert Record:
insert into student values (1, 'AA', 90);
insert into student values (2, 'BB', 80);
insert into student values (3, 'CC', 70);

Recalculate Marks by Adding 5:


update student set marks = marks + 5

Display Structure:
desc student;

Display Record:
select * from student;

Create Table:
create table student (StudentNo number(10),Name varchar2(25),Sub1 number(2), Sub2
number(2),Sub3 number(2),Total number(5),Average number(4,2),Result VARCHAR(10));

Insert sample data (optional)


INSERT INTO STUDENT (StudentNo, Name, Sub1, Sub2, Sub3) VALUES (1, 'AA', 40, 50, 30),
(2, 'BB', 20, 25, 30),
(3, 'CC', 50, 60, 70);
-- Calculate Total, Average, and Result
update student set Total = Sub1 + Sub2 + Sub3;
update student set Average = Total / 3.0;
update student set Result = 'PASS' WHERE Average >= 35;
update student set Result = 'FAIL' WHERE Average < 35;

-- Display the table with Total, Average, and Result


select Total, Average, Result from student;
OR
Select * from student;

Create Table:
create table student (StudentNo number(10),Name varchar2(25),Sub1 number(2), Sub2
number(2),Sub3 number(2),Total number(5),Average number(4,2));

Insert sample data (optional)


INSERT INTO STUDENT (StudentNo, Name, Sub1, Sub2, Sub3) VALUES (1, 'AA', 40, 50, 30),
(2, 'BB', 20, 25, 30),
(3, 'CC', 50, 60, 70);

-- Calculate Total, Average, and Result


update student set Total = Sub1 + Sub2 + Sub3; update student set Average = Total / 3.0;

Display the content of table


select * from student;
Create Table:
create table employee (EmpNo number(10),Name varchar2(25),BasicSalary number(6,2),DA
number(6,2),GrossSalary number(6,2),YearlySalary number(6,2),IncomeTax number(6,2));

-- Insert sample data (optional)


insert into employee (EmpNo, Name,
BasicSalary) values (1, 'John', 40000),
(2, 'Mary', 60000),
(3, 'Anna', 30000);

-- Calculate DA, Gross Salary, Yearly Salary, and Income Tax


update employee set DA = 0.45 * BasicSalary;
update employee set GrossSalary = BasicSalary + DA;
update employee set YearlySalary = GrossSalary * 12;
update employee set IncomeTax = YearlySalary * 0.15 WHERE YearlySalary > 500000;
update employee set IncomeTax = YearlySalary * 0.10 WHERE YearlySalary <= 500000

Display the table with calculations


select EmpNo, Name, BasicSalary, DA, GrossSalary, YearlySalary,
IncomeTax from employee;

NOTE BELOW SECTION ONLY FOR UNDERSTANDING PURPOSE

Step 1: Calculate the DA (Dearness Allowance) as 45% of the basic salary.


Step 2: Calculate the Gross Salary by adding the Basic Salary and DA.
Step 3: Calculate the Yearly Salary by multiplying the Gross Salary by 12 (months).
Step 4: Use two separate queries to calculate the Income
Tax: Apply a 15% tax rate if the Yearly Salary is above
500,000.
Apply a 10% tax rate if the Yearly Salary is 500,000 or
below. This approach is easier to understand and
beginner-friendly.

--

You might also like