0% found this document useful (0 votes)
224 views

Viva Questions For SQL & Java For STD 12

1. The document discusses various SQL concepts including database, DBMS, RDBMS, SQL, tables, fields, constraints, primary keys, unique constraints, foreign keys, and joins. 2. Key constraints discussed include primary keys which uniquely identify each record, unique constraints which ensure uniqueness of values in a column, and foreign keys which reference a primary key in another table to ensure referential integrity. 3. The different types of joins covered are inner joins which retrieve matching records from multiple tables, left outer joins which retrieve all records from the left table along with matching records from the right table, and right outer joins which are the opposite of left outer joins.

Uploaded by

eyadmukadam28
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
224 views

Viva Questions For SQL & Java For STD 12

1. The document discusses various SQL concepts including database, DBMS, RDBMS, SQL, tables, fields, constraints, primary keys, unique constraints, foreign keys, and joins. 2. Key constraints discussed include primary keys which uniquely identify each record, unique constraints which ensure uniqueness of values in a column, and foreign keys which reference a primary key in another table to ensure referential integrity. 3. The different types of joins covered are inner joins which retrieve matching records from multiple tables, left outer joins which retrieve all records from the left table along with matching records from the right table, and right outer joins which are the opposite of left outer joins.

Uploaded by

eyadmukadam28
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Viva Questions for SQL:-

1. What is Database?

A database is an organized collection of data, stored and retrieved digitally from a remote
or local computer system. Databases can be vast and complex, and such databases are
developed using fixed design and modeling approaches.

Create A Free Personalised Study Plan


Get into your dream companies with expert guidance

Real-Life Problems

Prep for Target Roles

Custom Plan Duration

Create My Plan

2. What is DBMS?

DBMS stands for Database Management System. DBMS is a system software responsible
for the creation, retrieval, updation, and management of the database. It ensures that our
data is consistent, organized, and is easily accessible by serving as an interface between the
database and its end-users or application software.

3. What is RDBMS? How is it different from DBMS?

RDBMS stands for Relational Database Management System. The key difference here,
compared to DBMS, is that RDBMS stores data in the form of a collection of tables, and
relations can be defined between the common fields of these tables. Most modern database
management systems like MySQL, Microsoft SQL Server, Oracle, IBM DB2, and Amazon
Redshift are based on RDBMS.

You can download a PDF version of Sql Interview Questions.


Download PDF
4. What is SQL?

SQL stands for Structured Query Language. It is the standard language for relational
database management systems. It is especially useful in handling organized data comprised
of entities (variables) and relations between different entities of the data.

5. What is the difference between SQL and MySQL?

SQL is a standard language for retrieving and manipulating structured databases. On the
contrary, MySQL is a relational database management system, like SQL Server, Oracle or
IBM DB2, that is used to manage SQL databases.

Learn via our Video Courses

RAHUL JANGHU
Python Course for Beginners With Certification: Mastering the Essentials

4.90

Enrolled: 90532

Free

MRINAL BHATTACHARYA
JavaScript Course With Certification: Unlocking the Power of JavaScript

4.8

Enrolled: 48017

Free
TARUN LUTHRA
Java Course - Mastering the Fundamentals

Enrolled: 95240

Free

SUBHESH KUMAR
Object Oriented Programming in Java Course Online

4.95

Enrolled: 4826

Free

SRIKANTH VARMA
Computer Networking Course: Master Computer Networking

Enrolled: 6391

Free

SRIKANTH VARMA
Operating System Course: Learn Fundamentals of Operating System

Enrolled: 6943

Free

JAMSHAID SOHAIL
PyTorch for Deep Learning Course

4.8

Enrolled: 1497

Free
SRIKANTH VARMA
Supervised Machine Learning Course

Enrolled: 4626

Free

SRIKANTH VARMA
Deep Learning Course: Deep Dive into Deep Learning

Enrolled: 2506

Free

SRIKANTH VARMA
Free Maths for Machine Learning Course

Enrolled: 3383

Free

SRIKANTH VARMA
Unsupervised Machine Learning Course

Enrolled: 1686

Free

YASH SINHA
Data Science Course - Mastering the Fundamentals

4.7

Enrolled: 11112

Free
GAURAV SISODIA
Keras & TensorFlow for Deep Learning

4.8

Enrolled: 1735

Free

ARNAV GUPTA
Spring Boot Course: Certified Course for Essential Skills

Enrolled: 7670

Free

PRATEEK NARANG
Maths for Programmers

Enrolled: 4506

Free

PRATEEK NARANG
Coding Essentials: Learn Logic Building for Beginners Free Course

Enrolled: 6384

Free

ARNAV GUPTA
Machine Coding Tic Tac Toe - LLD Case Study

Enrolled: 1450

Free
MRINAL BHATTACHARYA
Node JS Certification Course - Master the Fundamentals

4.8

Enrolled: 9923

Free

PRATEEK NARANG
SQL for Beginners: Learn SQL using MySQL and Database Design Course

Enrolled: 17025

Free

ADITYA JAIN
Data Structures in C++ Course

4.5

Enrolled: 14110

Free

SUBHESH KUMAR
Java DSA Course - Master the Fundamentals and Beyond

4.95

Enrolled: 22952

Free

JITENDER PUNIA
DSA Problem Solving for Interviews using Java

4.9

Enrolled: 33875

Free
SRIKANTH VARMA
DBMS Course - Master the Fundamentals and Advanced Concepts

Enrolled: 42534

Free

SRIKANTH VARMA
Python and SQL for Data Science

Enrolled: 37348

Free

SRIKANTH VARMA
EDA and Data Visualization Course in Data Science

Enrolled: 6728

Free

TARUN MALHOTRA
Dynamic Programming Course - Learn Optimizing Complex Problems

4.9

Enrolled: 5870

Free

SATYA SAI
String Pattern Matching: KMP Algorithm

4.95

Enrolled: 3544

Free
TARUN MALHOTRA
Quora System Design Course

4.9

Enrolled: 2404

Free

ANSHUMAN SINGH
Instagram System Design Course: From Concept to Reality

Enrolled: 12589

Free

MOHIT YADAV
SQL v/s NoSQL Course

4.8

Enrolled: 8013

Free

6. What are Tables and Fields?

A table is an organized collection of data stored in the form of rows and columns. Columns
can be categorized as vertical and rows as horizontal. The columns in a table are called
fields while the rows can be referred to as records.

7. What are Constraints in SQL?

Constraints are used to specify the rules concerning data in the table. It can be applied for
single or multiple fields in an SQL table during the creation of the table or after creating
using the ALTER TABLE command. The constraints are:

 NOT NULL - Restricts NULL value from being inserted into a column.
 CHECK - Verifies that all values in a field satisfy a condition.
 DEFAULT - Automatically assigns a default value if no value has been specified for
the field.
 UNIQUE - Ensures unique values to be inserted into the field.
 INDEX - Indexes a field providing faster retrieval of records.
 PRIMARY KEY - Uniquely identifies each record in a table.
 FOREIGN KEY - Ensures referential integrity for a record in another table.
Advance your career with Mock Assessments
Real-world coding challenges for top company interviews

Real-Life Problems

Detailed reports
Attempt Now

8. What is a Primary Key?

The PRIMARY KEY constraint uniquely identifies each row in a table. It must contain
UNIQUE values and has an implicit NOT NULL constraint.
A table in SQL is strictly restricted to have one and only one primary key, which is
comprised of single or multiple fields (columns).

CREATE TABLE Students ( /* Create table with a single field as primary key */
ID INT NOT NULL
Name VARCHAR(255)
PRIMARY KEY (ID)
);

CREATE TABLE Students ( /* Create table with multiple fields as primary key */
ID INT NOT NULL
LastName VARCHAR(255)
FirstName VARCHAR(255) NOT NULL,
CONSTRAINT PK_Student
PRIMARY KEY (ID, FirstName)
);

ALTER TABLE Students /* Set a column as primary key */


ADD PRIMARY KEY (ID);
ALTER TABLE Students /* Set multiple columns as primary key */
ADD CONSTRAINT PK_Student /*Naming a Primary Key*/
PRIMARY KEY (ID, FirstName);

write a sql statement to add primary key 't_id' to the table 'teachers'.

Write a SQL statement to add primary key constraint 'pk_a' for table 'table_a' and fields
'col_b, col_c'.

9. What is a UNIQUE constraint?

A UNIQUE constraint ensures that all values in a column are different. This provides
uniqueness for the column(s) and helps identify each row uniquely. Unlike primary key,
there can be multiple unique constraints defined per table. The code syntax for UNIQUE is
quite similar to that of PRIMARY KEY and can be used interchangeably.

CREATE TABLE Students ( /* Create table with a single field as unique */


ID INT NOT NULL UNIQUE
Name VARCHAR(255)
);
CREATE TABLE Students ( /* Create table with multiple fields as unique */
ID INT NOT NULL
LastName VARCHAR(255)
FirstName VARCHAR(255) NOT NULL
CONSTRAINT PK_Student
UNIQUE (ID, FirstName)
);

ALTER TABLE Students /* Set a column as unique */


ADD UNIQUE (ID);
ALTER TABLE Students /* Set multiple columns as unique */
ADD CONSTRAINT PK_Student /* Naming a unique constraint */
UNIQUE (ID, FirstName);

10. What is a Foreign Key?

A FOREIGN KEY comprises of single or collection of fields in a table that essentially


refers to the PRIMARY KEY in another table. Foreign key constraint ensures referential
integrity in the relation between two tables.
The table with the foreign key constraint is labeled as the child table, and the table
containing the candidate key is labeled as the referenced or parent table.

CREATE TABLE Students ( /* Create table with foreign key - Way 1 */


ID INT NOT NULL
Name VARCHAR(255)
LibraryID INT
PRIMARY KEY (ID)
FOREIGN KEY (Library_ID) REFERENCES Library(LibraryID)
);

CREATE TABLE Students ( /* Create table with foreign key - Way 2 */


ID INT NOT NULL PRIMARY KEY
Name VARCHAR(255)
LibraryID INT FOREIGN KEY (Library_ID) REFERENCES Library(LibraryID)
);

ALTER TABLE Students /* Add a new foreign key */


ADD FOREIGN KEY (LibraryID)
REFERENCES Library (LibraryID);

What type of integrity constraint does the foreign key ensure?

Write a SQL statement to add a FOREIGN KEY 'col_fk' in 'table_y' that references 'col_pk'
in 'table_x'.

11. What is a Join? List its different types.

The SQL Join clause is used to combine records (rows) from two or more tables in a SQL
database based on a related column between the two.
There are four different types of JOINs in SQL:

 (INNER) JOIN: Retrieves records that have matching values in both tables involved
in the join. This is the widely used join for queries.

SELECT *
FROM Table_A
JOIN Table_B;
SELECT *
FROM Table_A
INNER JOIN Table_B;

 LEFT (OUTER) JOIN: Retrieves all the records/rows from the left and the matched
records/rows from the right table.

SELECT *
FROM Table_A A
LEFT JOIN Table_B B
ON A.col = B.col;
 RIGHT (OUTER) JOIN: Retrieves all the records/rows from the right and the
matched records/rows from the left table.

SELECT *
FROM Table_A A
RIGHT JOIN Table_B B
ON A.col = B.col;

 FULL (OUTER) JOIN: Retrieves all the records where there is a match in either the
left or right table.

SELECT *
FROM Table_A A
FULL JOIN Table_B B
ON A.col = B.col;

12. What is a Self-Join?

A self JOIN is a case of regular join where a table is joined to itself based on some relation
between its own column(s). Self-join uses the INNER JOIN or LEFT JOIN clause and a
table alias is used to assign different names to the table within the query.

SELECT A.emp_id AS "Emp_ID",A.emp_name AS "Employee",


B.emp_id AS "Sup_ID",B.emp_name AS "Supervisor"
FROM employee A, employee B
WHERE A.emp_sup = B.emp_id;

Get Access to 250+ Guides with Scaler Mobile App!


Experience free learning content on the Scaler Mobile App

4.5
100K+
Play Store

13. What is a Cross-Join?

Cross join can be defined as a cartesian product of the two tables included in the join. The
table after join contains the same number of rows as in the cross-product of the number of
rows in the two tables. If a WHERE clause is used in cross join then the query will work
like an INNER JOIN.

SELECT stu.name, sub.subject


FROM students AS stu
CROSS JOIN subjects AS sub;
Write a SQL statement to CROSS JOIN 'table_1' with 'table_2' and fetch 'col_1' from
table_1 & 'col_2' from table_2 respectively. Do not use alias.

Write a SQL statement to perform SELF JOIN for 'Table_X' with alias 'Table_1' and
'Table_2', on columns 'Col_1' and 'Col_2' respectively.

14. What is an Index? Explain its different types.

A database index is a data structure that provides a quick lookup of data in a column or
columns of a table. It enhances the speed of operations accessing data from a database table
at the cost of additional writes and memory to maintain the index data structure.

CREATE INDEX index_name /* Create Index */


ON table_name (column_1, column_2);
DROP INDEX index_name; /* Drop Index */

There are different types of indexes that can be created for different purposes:

 Unique and Non-Unique Index:

Unique indexes are indexes that help maintain data integrity by ensuring that no two rows
of data in a table have identical key values. Once a unique index has been defined for a
table, uniqueness is enforced whenever keys are added or changed within the index.

CREATE UNIQUE INDEX myIndex


ON students (enroll_no);

Non-unique indexes, on the other hand, are not used to enforce constraints on the tables
with which they are associated. Instead, non-unique indexes are used solely to improve
query performance by maintaining a sorted order of data values that are used frequently.

 Clustered and Non-Clustered Index:

Clustered indexes are indexes whose order of the rows in the database corresponds to the
order of the rows in the index. This is why only one clustered index can exist in a given
table, whereas, multiple non-clustered indexes can exist in the table.
The only difference between clustered and non-clustered indexes is that the database
manager attempts to keep the data in the database in the same order as the corresponding
keys appear in the clustered index.

Clustering indexes can improve the performance of most query operations because they
provide a linear-access path to data stored in the database.

Write a SQL statement to create a UNIQUE INDEX "my_index" on "my_table" for fields
"column_1" & "column_2".

15. What is the difference between Clustered and Non-clustered index?

As explained above, the differences can be broken down into three small factors -

 Clustered index modifies the way records are stored in a database based on the
indexed column. A non-clustered index creates a separate entity within the table
which references the original table.
 Clustered index is used for easy and speedy retrieval of data from the database,
whereas, fetching records from the non-clustered index is relatively slower.
 In SQL, a table can have a single clustered index whereas it can have multiple non-
clustered indexes.

16. What is Data Integrity?

Data Integrity is the assurance of accuracy and consistency of data over its entire life-cycle
and is a critical aspect of the design, implementation, and usage of any system which stores,
processes, or retrieves data. It also defines integrity constraints to enforce business rules on
the data when it is entered into an application or a database.

17. What is a Query?

A query is a request for data or information from a database table or combination of tables.
A database query can be either a select query or an action query.

SELECT fname, lname /* select query */


FROM myDb.students
WHERE student_id = 1;
UPDATE myDB.students /* action query */
SET fname = 'Captain', lname = 'America'
WHERE student_id = 1;

18. What is a Subquery? What are its types?

A subquery is a query within another query, also known as a nested query or inner query.
It is used to restrict or enhance the data to be queried by the main query, thus restricting or
enhancing the output of the main query respectively. For example, here we fetch the contact
information for students who have enrolled for the maths subject:

SELECT name, email, mob, address


FROM myDb.contacts
WHERE roll_no IN (
SELECT roll_no
FROM myDb.students
WHERE subject = 'Maths');

There are two types of subquery - Correlated and Non-Correlated.

 A correlated subquery cannot be considered as an independent query, but it can refer


to the column in a table listed in the FROM of the main query.
 A non-correlated subquery can be considered as an independent query and the output
of the subquery is substituted in the main query.

Write a SQL query to update the field "status" in table "applications" from 0 to 1.

Write a SQL query to select the field "app_id" in table "applications" where "app_id" less
than 1000.

Write a SQL query to fetch the field "app_name" from "apps" where "apps.id" is equal to
the above collection of "app_id".

19. What is the SELECT statement?

SELECT operator in SQL is used to select data from a database. The data returned is stored
in a result table, called the result-set.

SELECT * FROM myDB.students;

20. What are some common clauses used with SELECT query in SQL?

Some common SQL clauses used in conjuction with a SELECT query are as follows:

 WHERE clause in SQL is used to filter records that are necessary, based on specific
conditions.
 ORDER BY clause in SQL is used to sort the records based on some field(s) in
ascending (ASC) or descending order (DESC).

SELECT *
FROM myDB.students
WHERE graduation_year = 2019
ORDER BY studentID DESC;

 GROUP BY clause in SQL is used to group records with identical data and can be
used in conjunction with some aggregation functions to produce summarized results
from the database.
 HAVING clause in SQL is used to filter records in combination with the GROUP BY
clause. It is different from WHERE, since the WHERE clause cannot filter aggregated
records.

SELECT COUNT(studentId), country


FROM myDB.students
WHERE country != "INDIA"
GROUP BY country
HAVING COUNT(studentID) > 5;
Viva Question on Java:-

1. What is Java?

Java is a platform-independent high-level programming language. It is platform-independent


because its byte codes can run on any system regardless of its operating system.

2. What are the features of Java?

 Object-oriented programming (OOP) concepts


 Platform independent
 High performance
 Multi-threaded

Java 17 Masterclass: Start Coding in 2023


Last Updated December 2023

Bestseller

 723 lectures

 All Levels

4.6 (191,511)
Acquire Key Java Skills: From Basics to Advanced Programming & Certification – Start Your
Dev Career | By Tim Buchalka, Tim Buchalka’s Learn Programming Academy

Explore Course

3. What are the OOP concepts?

 Inheritance
 Encapsulation
 Polymorphism
 Abstraction
 Interface

4. What is data encapsulation, and why is it useful?

Encapsulation is a concept in Object-Oriented Programming for combining properties and


methods in a single unit. Encapsulation helps developers follow a modular approach for
software development because each object has its own set of methods and variables and
serves its functions independent of other objects. In addition to that, encapsulation serves data
hiding purposes.

5. What is polymorphism?

Polymorphism is one interface with many implementations. This characteristic allows you to
assign a different meaning or usage to something in different contexts. For example, you can
use polymorphisms to enable more than one form for entities, such as variables, functions, or
objects.

6. What are the types of polymorphism, and how do they differ?

There are two types of polymorphism:

 Compile-time polymorphism is method overloading.


 Run-time polymorphism uses inheritance and interface.

7. What does an interface in Java refer to?

 An interface as it relates to Java is a blueprint of a class or a collection of abstract


methods and static constants.
 Each method is public and abstract, but it does not contain any constructor.

8. What are constructors in Java?

In Java, a constructor refers to a block of code used to initialize an object. In addition:

 Constructors must have the same name as that of the class.


 Constructors have no return type.
 Creating an object will call a constructor automatically.

9. Name and explain the types of constructors in Java.

The two types of constructors in Java are the Default Constructor and
the Parameterized Constructor.

 Default Constructor
o Does not take any inputs
o Main purpose is to initialize the instance variables with the default values
o Widely used for object creation
 Parameterized Constructor
o Capable of initializing the instance variables with the provided values.
o These constructors take the arguments.

10. What is JDK?

 JDK stands for Java development kit.


 It can compile, document, and package Java programs.
 It contains both JRE and development tools.
11. What is JVM?

 JVM stands for Java virtual machine.


 It is an abstract machine that provides a run-time environment that allows
programmers to execute Java bytecode.
 JVM follows specification, implementation, and runtime instance notations.

12. What is JRE?

 JRE stands for Java runtime environment.


 JRE refers to a runtime environment that allows programmers to execute Java
bytecode.
 JRE is a physical implementation of the JVM.

13. In Java, what are the differences between heap and stack memory?

Memory

 Stack memory is used only by one thread of execution.


 All the parts of the application use heap memory.

Access

 Other threads can’t access stack memory.


 Objects stored in the heap are globally accessible.

Memory Management

 Stack follows the LIFO manner to free memory.


 Memory management for heap stems from the generation associated with each object.

Lifetime

 Stack exists until the end of the execution of the thread.


 Heap memory lives from the start till the end of application execution.

Usage

 Stack memory only contains local primitive and reference variables to objects in heap
space.
 Whenever you create an object, it is always stored away in the heap space.

14. What is a JIT compiler?

A JIT compiler runs after the program is executed and compiles the code into a faster form,
hosting the CPU’s native instructing set.

15. How does a JIT compiler differ from a standard compiler?


JIT can access dynamic runtime information, and a standard compiler does not. Therefore,
JIT can better optimize frequently used inlining functions.

Top courses in Java

Develop Minecraft Plugins (Java)


Stephen King
4.8 (3,696)
Bestseller

Learn Selenium with Java, Cucumber + Live Project


Pavan Kumar
4.6 (5,345)
Bestseller

Java SE 11 Developer 1Z0-819 OCP Course - Part 1


Tim Buchalka, Tim Buchalka's Learn Programming Academy
4.3 (3,829)
Bestseller

Java Collections from basics to Advanced


Basics Strong
4.3 (1,365)

Java Programming for Complete Beginners


in28Minutes Official
4.5 (41,015)

Learn JAVA Programming - Beginner to Master


Abdul Bari
4.6 (16,761)

Java for Beginners


Navin Reddy
4.5 (840)

Core Java for Automation Testers- Coding made Easy


Rahul Shetty
4.6 (6,666)

Project Development Using Spring Boot


Bharath Thippireddy
4.3 (2,361)

Mastering Java Reactive Programming [ From Scratch ]


Vinoth Selvaraj
4.6 (1,689)
Highest Rated

Java Design Patterns


Bharath Thippireddy
4.7 (1,923)

Advanced One Day Java Workshop from Java 8 to 17


Arunan Ramanathan
4.4 (115)
>
More Java Courses

16. What is an inner class?

An inner class is a class that is nested within another class. An Inner class has access rights
for the class that is nesting it, and it can access all variables and methods defined in the outer
class.

17. What is a subclass?

A subclass is a class that inherits from another class called the superclass. Subclass can
access all public and protected methods and fields of its superclass.

18. What is a package in Java?

In Java, packages are the collection of related classes and interfaces which bundle together.

19. How can developers use packages in Java?

Packages in Java allow developers to modularize the code and optimize its reuse easily. In
addition, developers can use other classes to import and reuse the code within the packages.

20. What are the advantages of packages in Java?

 Packages help developers avoid name clashes.


 Packages provide easier access control.
 Packages can also contain hidden classes that are not visible to the outer classes and
are only used within the package.
 Packages create a standardized hierarchical structure, making it easier to locate related
classes

You might also like