You are on page 1of 36

Q1. Explain what is data?

Ans-->

Data: Raw unprocessed fact

Example: 25, Ram, Bhopal

Q2.Expalin Information?

Information: processed Data

Example: The Age of Ram is 25.

Q3. what is Database?

Ans--> Collection of related data.

Example: Online Banking System, Library Management System

Q4. Explain metadata?

Ans-->data about data is called metadata data

object in database is also called metadata.

The database definition

Q5. Explain DBMS?

Ans-->DBMS is a software tools which is used to managed data in


efficient way.
DBMS is an integrated set of programs used to create and maintain a
database

Q6. What is the functionalities of DBMS?

1. Define : Specifying the data type, and constraint for the data to be
stored.

2. construct: processing of storing data on some storage medium

3. manipulate: Querying the database to retrieve, insert update, delete


database and generating reports.

4. share: allows multiple users and programs to access the database


concurrently.

Q7. What is the properties of databases management system?

Ans-->

1. A database represents some aspects of the real world

2. A database is a logically collection of data with some inherent


meaning

3.A database is designed, built and populated with data for a specific
purpose
Q8. Applications of Databases?

Ans-

1. Banking

2.College and university

3. Railway Reservation System

4. e-commerce

5. Education Organization

--------------------------------------------------------------------------------------------

Q9. Explain types of data?

1. structured data: store in a particular way or structure

for example: tables

RDBMS:

Mysql

oracle

Ms Access

SQLite

SQL SERVER

Sysbase

DB2
2. un structured data:

to store in unstructured way

Example: MongoDB

-----------------------------------------------------------------------------------------------

RDBMS(SQL)

Oracle

Mysql

DB2

Sysbase

Sql Server

SqLite

MS Access

-------------------------------------------------------------------------------------------
Q1. Explain SQL?

Ans->SQL is a structured Query Language developed in 1970s by IBM


researchers.

Sql is case insensitive programming language it means uppercase and


lowercase both are same here

Sql is Language of All RDBMS

1. MySql

2.Oracle

3. Sql Server

4. Sqlite
5. DB2

Q2. what can sql Do?

Ans-->

1. Sql can execute Queries

2. Sql can retrieve data from the database

3. Sql can insert record in a database

4. Sql can update record in a database

5. Sql can delete record from the database

6. Sql can create new database

7. Sql can delete database

8. Sql can create table

9. sql can update table

10. sql can add column

11. Sql can delete column

12. Sql can add constraint

13. sql can create procedure and function in a database

14. sql can create view in a database

15. Sql can set permission on database, procedure and views


Sql is nothing but language of database

-----------------------------------------------------------------------------------------------

Q3. Explain SQL Statement?

Ans-->SQL Statement are categorized into four different types of


statement

1. DDL: DDL(Data Definition Language) Actually consist of the sql


commands that can be used to define the database schema. DDL allows
to modify/add/delete the logical structure of the of the database

Example:

1. create

2. Alter

3. drop

4. truncate

5.rename

2. DML : DML(Data Manipulation Language)

The Sql Commands that deals with the manipulation of data present in
the database belong to DML or data manipulation.

1. insert

2. update
3. delete

4. select

3. DCL :(Data Control Language):

Data Control Language is used to control privileges in database. To


perform any operation in the database such creating table, update data

1. grant

2. revoke

4. TCL: (Transaction Control Language)

Transaction Control Language used to manage the transaction

1. commit(commit command is used to permanently save any


transaction in the database)

2. rollback

3. save point
Q1. Explain How to create Database in mysql?

Ans--> if we want to create database in mysql then we should go for


DDL (create)

Syntax:

create database database_name;

create database lnctdemo;

Q2. How to delete database?

Ans-->if we want to delete database object then we should go for drop

Syntax:

drop database database name;

drop DATABASE lnctdemo

Q3. How to create table in mysql?

Syntax:

create table table_name(

column data type(size),

column data type(size),

column data type(size)

)
emp

EMPNO NAME SAL DEPNO

in Mysql

__________

create table emp(

empno int,

name varchar(30),

sal float,

deptno int

Q4. How to use my database

use database name;

use lnctdemo;
Q5. How to display structure of the table?

Ans-->

Syntax:

desc tablename;

desc emp;

describe tablename

describe emp;

Q6. How to add new column in existing table

emp

EMPNO NAME SAL DEPNO comm

Syntax:

alter table tablename add column column_name data type;

alter table emp add column comm int;

-------------------------------------------------------------------------------------------
Q6. How to change data type of existing column

Syntax:

alter table tablename modify column column_name data type;

alter table emp modify column comm float;

Q7. How to delete column in a table

emp

EMPNO NAME SAL DEPNO comm


101 AMAN 12000 10 500.50

alter table tablename drop column column_name;

alter table emp drop comm;


Q1.How to rename existing table in mysql?

Ans->

Syntax:

alter table table_name rename to new_table_name;

alter table emp rename to employee;

employee

EMPNO NAME SAL DEPNO


101 AMAN 12000 10

customer

EMPNO NAME SAL DEPNO


101 AMAN 12000 10

Q2. create another table from select statement

Ans--> you can create one table from another table by adding select
statement at the end of create table statement

Syntax:
create table table_name as select * from original_table_name;

create table employee as select * from emp;

--------------------------------------------------------------------------------------------

Q3. How to delete table in a database;

Ans--> if we want to delete table structure then we should go for drop


command

Syntax:

drop table tablename;

drop table xyz;

-----------------------------------------------------------------------------------------------

Alter-----> change existing database object

Drop-------->delete structure of database Object + data

Rename------>to change a name

Create--->create something

---------------------------------------------------------------------
Q4. Explain insert command?

Ans--> The insert command is used to insert new record in a table

it is possible to write insert command in two ways

1. specify only values to be inserted but in this case mandatory to fill


value of all column.

Syntax:

insert into table name values(value1,value2,value3,value4);

insert into emp values(101,'Deepak',12000,10);

insert into emp values(102,'sanjay',34000,20);

2. Specify both column and values to be inserted in this case not


mandatory to fill all column

Syntax:

insert into table name(column1, column2) values(value1, value2)

insert into emp(empno,name) VALUES(103,'Sanjay');

insert into emp(name,empno) VALUES('kartik',104);

emp

EMPNO NAME SAL DEPNO


101 Deepak 13200 10
102 sanjay 37400 20
103 Aman 50600
104 Kartik
105 Shivam 3333 20

Q2. How to add primary key in existing table.

Syntax:

alter table tablename add primary key(column);

alter table emp add primary key(empno);

Q1. How to update data in a table?

Ans-->if we want to update data in a table then we should


update(DML).

Syntax:

update table name set column=value, column=value where pk=value;

update emp set sal=3456, deptno=30 where empno=103;

update emp set sal=6666 WHERE empno=101;

Q2. How to increase salary of employee by 10%

update emp set sal=sal+sal*0.1;


Q3. How to delete data from the table

Ans-->if we want to delete data from the table then we should go for
delete(DML)

Syntax:

delete from table name where pk=value;

delete from emp where empno=104;

Q4. How to select data from the table

Ans--> if we want to retrieve data from the table then we should go for
select command

Syntax:

Select * from table name;

select * from emp;

Syntax:

select column name, column name from table name;

select name, empno from emp;

Q2. select all employee data whose empno>=105

select * from emp where empno>=105;


Q3. select all employee whose salary is null;
select * from emp where sal is null

Q1. Select All employee whose deptno is 10.

Query:

select * from emp where deptno=10;

Q2. Select All employee whose deptno is not 10.

Query:
select * from emp where deptno not in (10)

select * from emp where deptno!= 10;


select * from emp where deptno <> 10

Q3. select all employee whose salary>15000;

Query:

select * from emp where sal>15000;


Q4. select all employee whose salary>15000 and deptno is 10;

Query:

select * from emp where sal>15000 && deptno=10;

select * from emp where sal>15000 and deptno=10;

Q3. select all employee whose salary>15000 and deptno is 10,also


empno is greater 105;

Query:

select * from emp where sal>15000 and deptno=10 and empno>105;

Q4. Explain distinct statement?

Ans--> The select distinct statement is used to return only different


values.

A column often contains many duplicate values, and sometimes you


only want to list of distinct values

Syntax:

select distinct column from table name;


Q1. how to find unique deptno in a table.

Query:

select distinct deptno from emp;

select distinct sal from emp;

select distinct name from emp;

select DISTINCT name,deptno from emp;

-----------------------------------------------------------------------------------------------

Q2. Select All employee data from the emp table whose deptno is 10 or
salary > 15000.

Ans-->

Query:

select * from emp where sal>15000 or deptno=10;

select * from emp where sal>15000 || deptno=10;

-----------------------------------------------------------------------------------------------

Q1. Explain group function / Aggregate Function in SQL?

Ans--> An aggregate function performs a calculation on a set of values,


and returns a single value, aggregate function ignore null values.

we discuss following group function / Aggregate function

1. sum()

2. max()
3. min(()

4. avg()

5. count()

Q1. Explain sum function in sql?

Ans--> sum of all non null values of a column

Syntax:

sum(column name);

sum(distinct column name);

select sum(sal) from emp;

select sum(DISTINCT sal) from emp;

Q1. Explain avg function in sql?

Ans--> if we want to find avg of values

sum(sal)/count(sal);

Syntax:

avg(column name);

avg(distinct column name);

select avg(sal) from emp;


select avg(DISTINCT sal) from emp;

Q1. Explain max function in sql?

Ans--> The Sql max function is used to return the maximum value of an
expression in a select statement.

Syntax:

select max(column) from table name;

select max(sal) from emp;

Q2. write a query to find max salary of employee whose deptno is 10.

select max(sal) from emp where deptno=10;

Q3. write a query to find max salary of employee whose empno less
than 108.

ANs-->select max(sal) from emp where empno<108;

Q2. Explain min function in Sql?

Ans--> The min function returns the smallest value of the selected
column.

Syntax:

select min(column name) from table name;

select min(sal) from emp;


Q2. write a query to find min salary of employee whose deptno is 10.

select min(sal) from emp where deptno=10;

Q3. write a query to find min salary of employee whose deptno not 10.

select min(sal) from emp where deptno<>10

Q4. Explain count function in sql;

Ans-->The Sql count function returns the number of rows in a table


satisfying the criteria specified int the where clause. it sets the number
of rows or non null columns. count() returns 0 if there were no
matching rows.

Syntax:

select count(*) from table name;

select count(column name) from table name;

select count(column name ) from table name where condition

Example :

Q1. write a query to find number of employee in emp table.


select count(*) from emp

select count(empno) from emp


Q1. write a query to display Total salary of the employee

select sum(sal) as Total_Salary_Of_The_Employee,avg(sal) as


Average_Salary_OF_The_Employee from emp;

select sum(sal) as Total_Salary_Of_The_Employee,avg(sal) as


Average_Salary_OF_The_Employee,max(sal) as
Maximum_Salary,min(sal) as minimum_Salary from emp;

select sum(sal),max(sal),avg(sal),min(sal) from emp;

----------------------------------------------------------------------------

Q2. Explain dual table in sql?

Ans--> The dual is a special one row, one column table present by
default in all oracle databases.

Q3.Explain Round function in sql?

Ans-->This function in sql is used to round off a specified number to a


specified decimal places
select round(123.5678,2) from DUAL

output: 123.57

select round(123.5678,0) from DUAL


output: 124

select round(123.5678,1) from DUAL

output: 123.6

select round(123.5678,-1) from DUAL

output: 120

select round(127.5678,-1) from DUAL

output: 130
select round(125.5678,-1) from DUAL

output: 130

select name,round(sal,-2) from emp

Q3. Explain ceil function in sql?

Ans-->SQL ceil() function is used to get the smallest integer which is


greater than, or equal to, the specified numeric expression .
select ceil(126.56) from dual

Output: 127

select name,ceil(sal) from emp;

--------------------------------------------------------------------------------------------
Q1. Explain floor function in sql?

Ans-->The floor function returns the largest integer value that is smaller
than or equal to a number.
SELECT floor(25.7)

Q2. Explain truncate function in sql?

Ans-->Te truncate function truncates a number to the specified number


of decimal places.

Syntax:

trucate(number,decimal);
select truncate(345.159789,2)

----------------------------------------------------------------------------------------------

Q3. Explain pow() function in sq?

Ans-->Sql pow function returns the value of a number raised to the


power of another number

Syntax:

pow(number,power);

select pow(2,3)

output: 8
select pow(3.333,1.5555)
Q1. Explain in operator in sql?

Ans--> The in operator allows you to specify multiple values in a where


clause

The IN operator is a shorthand for multiple conditions

Syntax:

select column List from table name where column IN(value1,value2);

T yp1

select * from emp where deptno=10 or deptno=20

select * from emp where deptno in(10,20);

Q1. Explain not in operator in sql?

Ans--> The not in operator is just opposite of in operator it will return


all data not in a list

Syntax:

select column List from table name where column not


IN(value1,value2);

select * from emp where deptno not in(10,20);


Q3. Explain between Operator in sql?

Ans-> The SQL between operator select values within a given range.
The values can be number, text or dates

Syntax:

select column list from table name where column name between value
1 and value 2

select * from emp where sal between 1000 and 25000;

select * from emp where sal not between 1000 and 25000

select * from emp where sal in (11000,12000) or deptno=10


Q1. Explain order by clause in SQL?

Ans-->The order by keyword is used to sort the result-set in ascending


order or descending order.

by default order by is an ascending order. to sort the records in


descending order use the desc keywords

Syntax:

select * from tablename order column name asc|Desc;

Q1. write a query to sort all employee data on the basis of salary in
ascending order.

Ans

select * from emp order by sal;

Q1. write a query to sort all employee data on the basis of salary in
descending order.

Ans

select * from emp order by sal desc;

Q3. write a sql query to sort data of employee on the basis of employee
name in ascending order.

select * from emp order by ename;


Q3. write a sql query to sort data of employee on the basis of employee
name in decending order.

select * from emp order by ename desc;

Q4. Explain group by clause in sql?

Ans-->The group by clause groups row that have the same values into
summary rows like "find the number of customers in each country"

find the number of job in each department.

The group by statements is often used with aggregate


function(max(),min(),avg(),sum(),count()) to group the result-set by
one or more columns

Syntax:

select column_list

from table name

where condition

group by column name;


Q4. Explain HAVING clause in sql?

ANs-->The having clause was added to sql because the where keyword
cannot be used with aggregate function

Syntax:

select column list

from tablename

where condition

group by column

having condition

order by column name.

Q3. write a query to display those department having more than 3


employee from emp table.

Ans-->

select deptno from emp group by deptno having count(*)>3;


Syntax of like operator

select column list from table name where like 'char pattern';

Q1. write a Query to display the employee whose name start with Caps
letter A from emp table;

select * from emp where ename like 'A%';


Q2. write a query to display the employee whose name having caps
Letter A in any position by using like operator.

select * from emp where ename like '%A%';

Q3. write a query to display all employee whose name second letter is
caps A.

select * from emp where ename like '_A%';

Q4. write a query to display all employee whose name third letter is
caps A.

select * from emp where ename like '__A%';

Q4. write a query to display the employee who are join in the year of
81.

select * from emp where hiredate like '%81%';

Q1. Cross Join

select * from emp cross join dept;


select * from emp,dept;

Q2. write a query to display name and location of the employee

Q5. write a query to display the employee whose name ends with N.

select * from emp where ename like '%N';

Q5. write a query to display the employee whose name ends second
last char with E.

select * from emp where ename like '%E_';


outer join

Left outer Join

select * from emp left join dept ON emp.deptno=dept.deptno;

Right outer Join

select * from emp left join dept ON emp.deptno=dept.deptno;

Full Join / full outer join

SELECT *

FROM emp a FULL OUTER JOIN dept d

ON (a.deptno = b.deptno);

---------------------------------------------------------------------------------------
Q1.Explain SQL Constraint?

Ans->SQL Constraint are used to specify rules for data in a table

constraint can be specified when the table is created with the create
table command or, after table is created with the alter command

constraint are used to limit the type of data that can go into a table.

1. Not Null: Ensures that a column cannot have null value.

2. Unique: Ensures that all values in a column are different

Note: unique constraint can have a null values.

Q2. Explain Primary Key in sql?

Ans-->The Primary Key constraint uniquely identifies each record in a


table

Primary key must contain unique values, and cannot contain null
values.

A table can have only on primary key, and in the table, this primary key
can consist single or multiple columns (composite primary key)

You might also like