You are on page 1of 10

1.What is SQL?

Ans. Structured Query Language which is used to create and access the database to
support software application.

2.What are the tables in SQL?


Ans. A table is a collection of records which contains tuples(rows) and
attributes(columns).

3.What are the different types of statements in SQL?


Ans. 1)DDL:Data Definition Language-CREATE,ALTER,DROP,TRUNCATE.
2)DML:Data Manipulation Language-INSERT,DELETE,UPDATE.
3)DCL:Data Control Language-GRANT,REVOKE.
4)DQL:Data Query Language-SELECT.

4.How do we use distinct statement?


Ans. DISTINCT statement is used with the select statement if the record contains
duplicate values.
Then DISTINCT is used to select different values among the duplicate records.

5.What are the different clauses used in MySQL?


Ans. 1)SELECT
2)FROM
3)WHERE
4)GROUP BY
5)HAVING
6)ORDER BY
7)USING

6.What is constraints? Why we use constraints?Which constraint you want to create a


database?
Ans. Constraints are used to set the rules for all records in the table.
If any constraint get violated then the action will be abort.
Constraints are defined while the table is created
Types of Constraints :
1)NOT NULL
2)UNIQUE
3)P.K
4)F.K:Under the concept of referential integrity that references other table
with the help of primary key.
5)CHECK

7.What is Joins and what are the types of Joins?


Ans. Joins are used to join multiple tables with the help of primary key and
foreign key.Types are inner,left outer,right outer & cross join but no full
outer join in MySQL.

8.What are transaction and its controls?


Ans. Transaction can be defined as a sequential task on the database in a logical
manner to get the result.
Transaction controls are:
1.Commit 2.Rollback 3.Set transaction 4.Savepoint

9.What are the properties of transaction?


Ans.ACID
A-Atomicity:To ensure the correctness of all the transactions performed.
C-Consistency:Successful transaction have to work properly.
I-Isolation:If we are changing in one transaction it will not affect in other
transaction.
D-Durability:Even that the changes made in the database with committed
transaction persist as it is even afer system failure.

10.How many aggregate functions are available in SQL?


Ans.Aggregate function calculates the value from the multiple columns and return in
a single value.
FIRST() AVG() COUNT() MAX() MIN() SUM()
LAST().

11.What are scalar functions in SQL?


Ans.Scalar functions are used to return the single values based on the input
values.
UCASE() LCASE() ROUND() LEN() FORMAT().

12.What is view in SQL?


Ans.View is defined as a virtual table that contains rows and columns with fields
from one are more table
Create view viewname AS select coloumn_name from table_name where condition;

13.How can you update the views in SQL?


Ans. Replace view viewname AS select coloumn_name from table_name where condition;

14.Explain the working of SQL privileges?


Ans.There are two types of privleges.
Grant and Revoke commands are used to implement privileges in SQL multiple
user administartor.
The administrator of the database can grant or revoke privilges to or from
the user.
1.Grant-Syntax: grant privilege on object name to {username/public/role_name}
with grant option.
2.Revoke-Syntax: revoke privilege on object name from
{username/public/role_name}

15.How many types of privileges are availabe in SQL?


Ans. System privilege:Specify the rights to perform one or more actions on it which
includes admin allows a user to perform administrative task
such as (create,alter,delete the table) and
(create,alter,delete the views) and (alter the index).
Object privilege:This allows to perform action on an object or object of
another user such as EXECUTE,INSERT,UPDATE,DELETE,LOAD,FLUSH,etc.

16.What is the difference b/w SQL and MySQL?


Ans.
SQL MySQL
SQL is a structured query language used for manipulating MySQL
itself is a relational database which uses SQL as standard
and accessing.
query language.
17.What is cartesian product of the table?
Ans. The output of the cross join is called cartesian product.
It returns a row by combining each row from one table and each row of another
table.
Ex:Table-1 contains 10 rows and Table-2 contains 15 rows then the output
will be 150 rows.

18.What is the NVL function?


Ans. Converting a null value to actual value.

19.What do you mean by subquery?


Ans. A query within another query is known as subquery or nested query which
returns the output that is to be used by another query.

20.How many row comparision operators are used while working with subquery?
Ans. IN,ANY(SOME),ALL.

21.What is index in MySQL?


Ans. A index is a data structure that improves the speed of operations in a table.
Index can be created using one or more columns.

22.What is the difference b/w delete and truncate?


Ans. delete
truncate
1)delete comes under DML. 1)truncate
comes under DDL.
2)delete can be used to delete a specific row.
2)truncate can be used to remove all rows.
3)We can use delete with where clause.
3)truncate with where clause is not possible.

23.What is the difference b/w drop and truncate?


Ans. drop
truncate
In drop structure will be lost. In
truncate stucture will not be lost.

24.What is wild card operator?


Ans. It is also called LIKE operator.

25.What is the difference b/w nested subquery and corelated subquery?


Ans. Nested subquery
Corelated subquery
A subquery within another subquery is called nested subquery.
If output of the subquery depends on column value of the
parent query table then it is
called as corelated subquery.

26.What is Normalization? What are the types of Normalization?


Ans. Normalization is used to organize the data in such a manner the data
redundancy will never occur in database.
Types of Normalization:
1)1NF:It removes all the duplicate columns from the table and identfies the
unique column values.
2)2NF:It follows the 1NF and it shows partial dependency and defines a
relationship b/w tables using primary key.
3)3NF:It follows the 1NF and it shows full dependency and defines a
relationship b/w tables using primary key.

27.What is relationship?What are the types of relationship?


Ans. Relationship is a connection b/w one or more table in a database.
1.One to one relationship
2.One to many
3.Many to one
4.Many to many.

28.How to select all the records from the table?


Ans. Select is a statement to retrieve the data from database.
select [columnnames] from tablename;

29.What is the syntax to add a record to the table?


Ans. insert into tablename values (column1,...n);

30.How do a add a column to a table?


Ans. Alter is the statement to add column to a table
alter table tablename add columnname;

31.Define SQL delete statement?


Ans. Delete is used to delete the row from table;
delete from tablename where condition;

32.Define commit?
Ans. Commit is to save the changes made in the transaction.

33.Define rollback?
Ans. The changes which we made in the commit will be back.
Undo the changes made in the transaction.

34.What is primary key?


Ans. A primary key is a column whose values are unique in a row.
Primary key does not support null values.It is unique and should not be
duplicate.

35.What is candidate key?


Ans. A candidate key is a column or set of columns.
It should be unique.
Each table may have one or more candidate keys but each candidate key must be
unique like a primary key.
The candidate key purpose is for identifying.

36.What is composite key?


Ans. More than one primary key is called composite key.
Nature should be like primary key.

37.What is foreign key?


Ans. Foreign key is under the concept of referential integrity.
The foreign key references another table which having primary key and matches
the columns and retrieve the data.

38.What is check constraint?


Ans. Check constraint is giving some conditions

39.What is not null constraint?


Ans. It should accept any values.
It should not be not null..Ex:primary key

40.Is it possible for the table to have more than one primary key?
Ans. No.

41.Is it possible for the table to have more than one foreign key?
Ans. Yes.

42.What are the possible values for boolean data field?


Ans. true:1 in SQL true:-1 in MySQL.
false:0 false:0

43.How to select random rows from the table?


Ans. SAMPLE
select * from Hon sample(5);
44.Explain DML & DDL?
Ans. DML(Data Manipulation Language):Insert,Update,Delete
DDL(Data Definition Language):Create,Alter,Drop,Rename.

45.What is DQL?
Ans. DQL(Data Query Language):Select is used to retrieve the data from table.

46.What is DCL?
Ans. DCL(Data Control Language):

47.Can we rename a column in MySQL query?


Ans. Yes.
alter table tablename RENAME [old columnname] TO [new columnname];

48.Give the order of SQL select?


select from where group by having order by
a)order by is optional or not?--Optional.
b)What is the use of having?--When we use group by we have to use having..
c)What is the use of where?--condition.
d)What is the difference b/w where and group by?
e)What is the use of group by?
f)Is having necessary when we use group by? Yes.

49.What is MySQL comments?


Ans. -- is for SQl.
# is for MySQL.

50.Define UNION,MINUS,UNION ALL & INTERSECT?


Ans. UNION:Union returns ALL distinct rows selected by query.
UNION ALL:UnionAll returns ALL rows including duplicates.
MINUS:Returns all distinct rows selected by the first query not by the second.
Intersect:Returns all distinct rows selected by both queries.

51.What is the difference b/w unique constraints and primary key constraints?
Ans. Primary key is applicable for only one column where as unique constraints are
applicable for multiple columns.

52.What is referential integrity?


Ans. A referential integrity constraint is specified b/w two relations and it is
used to maintain the consistency among tuples in two relations.

53.Explain the difference b/w rename and alias?


Ans. A rename is the permanent name given to a column or table where as alias is
the temporary one.

54.What are the advantages of views?


Ans. A view restrict access to the data because view can dispaly selective columns
from the table.
View can be used to retrieve the simple queries from complex queries.

55.What is difference b/w local and global temporary table?


Ans. Local Global
In a compound statement a local temporary table is only In a
compound statement a global temporary table is
for the duration of the statement. for
permanent of the statement.

56.What is Data integrity?


Ans. Data integrity refers to maintaining and assuring the accuracy and consistency
of data in RDBMS system.
Data integrity will increase
1.Performance
2.Stability
3.Maintainability
4.Reusability.

57.What is entity integrity?


Ans. Entity integrity is a integrity rule that every table must have a primary key
and the columns choosen to be the primary key should be unique and not null.
Entity integrity ensures that the data you store remains in a proper format.

58.What is sequence generators?


Ans. The starting value of an auto increment is 1 and it is increased by 1.
Each table has only one auto increment column and it should be a integer.

59.What are the types of operators in MySQL?


Ans. Arithmetic operators
Comparision operators
Logical operators
Set operators.

60.What is arithmetic operators?


Ans. Arithmetic operators are used to manipulate numeric operands which are columns
storing numeric values.
Note:If a value of any operand in a numeric value expression is null then the
result of the expression is null.

61.What are the types of arithmetic operators?


Ans. 1.Monadic operators
2.Dyadic operators.

62.What is monadic arithmetic operator?


Ans. +,-

63.What is dyadic arithmetic operator?


Ans. /,*

64.What is comparision operator?


Ans. It is used to compare two operand and returns true or false or null.
Types are
=
!=
<
>
<=
>=

65.Difference b/w in & not in?


Ans. IN NOT IN
Comparing the operands with list of values if it matches then returns true.
Comparing the operands values with list of values
if it not matches then it returns true.

66.What is BETWEEN AND?


Ans. BETWEEN 1000 AND 2000

67.What is NOT BETWEEN AND?


Ans. NOT BETWEEN 1000 AND 2000
68.What is IS NULL?
Ans. select columnname from tablename where condition is null;

69.What is IS NOT NULL?


Ans. select columnname from tablename where condition is not null;

70.What is LIKE operator?


Ans. select columnname from tablename where condition like %;

71.What is NOT LIKE operator?


Ans. select columnname from tablename where condition not like %;

72.What is logical operator?


Ans. It is used for manipulating the results of more than one condition.

73.What are the types of logical operators?


Ans. NOT:Returns true if condition is false and returns false if condition is true.
AND:Returns true if both conditions are satisfied.
OR:Returns true if any one condition is satisfied.

74.What is set operator?


Ans. It is used to combine two queries to give a single result.
The two queries should be from same table or from a different table.

75.What are the types of set operators?


Ans. UNION
UNION AL
INTERSECT
MINUS

*76.What are the rules of set operator?


Ans. Both queries should have same no.of columns.
The column should be of same datatype.

77.What is MySQL function?


Ans. MySQL functions are used in SQL statements to perform logic or functionality.
Ex.Rounding the number.

78.What is aggregate function?


Ans. Gets values from multiple column and produces a single column.
AVG() MIN() MAX() COUNT() SUM() FIRST() LAST()

79.What is build-in scalar functions?


Ans. current_date,current_time,current_timestamp,current_sysdate
current_user,system_user

80.What is string function?


Ans. String functions accept character value as a input and can return both
character and numeric.
Some String functions are
LOWER()
UPPER()
SUBSTRING()
CONCAT()
TRIM()

81.What is numeric or mathemeatical function?


Ans. It accept the numerical values as input and produces as output.
ABS()
CEIL()
FLOOR()
ROUND()
MOD()
SQRT()

82.What are the types of string functions?


Ans. LOWER()
UPPER()
SUBSTRING()
CONCAT()
TRIM()

83.What are the types of numeric or mathematical functions?


Ans.
ABS()
CEIL()
FLOOR()
ROUND()
MOD()
SQRT()
84.What is date-time function?
Ans. Which returns the date and function.

85.What are the types of date-time function?


Ans. ADD_DATE()
CURENT_DATE()
CURRENT_TIME()
CURRENT_TIMESTAMP()

86.What is collasce function?


Ans. It returns only first non-null values in the list.
select COLLASCE(NULL,NULL,APPLE);

87.What is null if function?


Ans. NULL IF compares and returns the value
If both the columns are equal it returns null otherwise it returns the value
of the first column.

88.What is control flow function?


Ans. It is similar to the if else logic.
CASE VALUE WHEN [compare] THEN RESULT(WHEN [COMPARE] THEN RESULT...)[ELSE
WHEN RESULT] END
Scenario:I want to select the country name and customer name.If country name is
UK then it should be printed as United Kingdom or USA means
United States of America otherwise not applicable.
select customername,country CASE country WHEN UK THEN "United Kingdom"
WHEN USA THEN "United States of America"
ELSE "Not applicable" END;

89.What is nesting function?


Ans. A function inside the function is called nested function.
select func(func());
Ex:select SUM(10,NLLIF(12,13));

90.What is SQL expression?


Ans. SQL expression is a combination of one or more conditions,values,operators and
SQL functions to evaluate the value.
There are 5 types of expressions:
1.Simple expression
2.Compound expression
3.DateTime expression
4.Function expression
5.CASE expression

91.What is inner join?


Ans. Inner join keyword selects records that have matching values in both the
tables.
select (columnname1) from table1 inner join table2 on
table1.columnname1=table2.columnname1;

92.What is left outer join?


Ans. It returns all the values from the left of table-1 and matching values from
right of table-2.
select (columnname1) from table1 leftouter join table2 on
table1.columnname1=table2.columnname1;

93.What is right outer join?


Ans. It returns all the values from the right of table-1 and matching values from
left of table-2.
select (columnname1) from table1 rightouter join table2 on
table1.columnname1=table2.columnname1;

94.Is full outer join supported in MySql?


Ans. It returns the values from either left of the product or right of the product.
select (columnname1) from table1 fullouter join table2 on
table1.columnname1=table2.columnname1;

95.What is cross join?


Ans. The output of cross join is called cartesian product.
select columnnames from table1 cross join table2.

96.What is subquery insert statement?


Ans. Scenario:Consider a officers table.The columns are employeeid,employeename and
employeeadress.
Create table officers(employeeid int(10),employeename varchar(20) and
employeeadress varchar(30))
insert values
After creating a officers table we can copy the records from officers table to
a new table which having address is USA.
insert into new values(slect * from officers where employeeaddress in (select
employeeaddress from officers where employeeaddress='USA'));

97.What is subquery update statement?


Ans. Scenario:Want to update values in a new tables of USA to India
update tablename set columnname=value where columnname in (

98.What is subquery select statement?


Ans. Scenario:Want to display name and the phonenumber of the customers table who
have made the payments in payment table.
select customername,phonenumber from customers where customerid in(select
payment from customers);

99.What is subquery delete statement?


Ans.

100.What is scalar subquery?


Ans. Scalar subquery returns a variable like number,date and string.

101.What is single row subquery?


Ans. Scenario:Want to display the ordernumber and date for all orders which is
available in orders table whose date is less than the payment date
for checknumber ABCD.
select o.ordernumber,o.date from orders o where o.date< (select p.date from
payment p where p.checknumber='ABCD');

102.What is multiple row subquery?


Ans. Only IN operator is used in multiple subquery and no comparision operators.
select o.ordernumber,o.date from orders o where o.date in (select p.date
from payment p where p.checknumber='ABCD');

103.What is the use of in,not in,any,all,some in subquery?


Ans. IN:The subquery condition is true when the value of the expression matches for
one or more values.
NOT IN:The subquery condition is true when the value of the expression matches
for none of the values.
ALL:The subquery condition is true when the value of the expression matches
for every value.
ANY(SOME):The subquery condition is true when the value of the expression
matches atleast one value.

104.What is exist and not exist?


Ans. The EXIST operator is used to test the existance of any record in the
subquery.
select columnnames from tablename where EXISTS (select columnname from
tablename where condition);
Viceversa of EXISTS is set to be as NOT EXISTS.
select columnnames from tablename where NOT EXISTS (select columnname from
tablename where condition);

105.How will you create a index?


Ans. create index index_name on table_name (column1,...,n);

106.How will you drop a index?


Ans. drop index index_name on table_name;

107.How will you create a view?


Ans. create view view_name AS (select columnnames from table where condition);

108.How will you drop a view?


Ans. drop view view_name;

You might also like