Showing posts with label Database Interview Questions. Show all posts
Showing posts with label Database Interview Questions. Show all posts

June 11, 2022

What is SQL injection and how to prevent it in Java?



In this post, we will learn about common coding mistakes in Java, which lead to a vulnerable application. Also, we are going to learn to avoid SQLi.

What is SQL injection?
SQLi or SQL injection is an attack where a hacker manages to inject unauthorized SQL query language code into an application. Due to this, the attacker manages to change the behavior of a legitimate query before it hits the database.

April 17, 2020

Part 6: Elastic Search Interview Questions And Answers(Hands On)

Explain Bool Query in ElasticSearch.
A query that matches documents matching boolean combinations of other queries is called Bool Query. It is built using one or more boolean clauses, each clause with a typed occurrence. 

  • must: The clause (query) must appear in matching documents and will contribute to the score.
  • filter: The clause (query) must appear in matching documents. However unlike must the score of the query will be ignored. Filter clauses are executed in filter context, meaning that scoring is ignored and clauses are considered for caching.
  • should: The clause (query) should appear in the matching document.
  • must_not: The clause (query) must not appear in the matching documents. Clauses are executed in filter context meaning that scoring is ignored and clauses are considered for caching. Because scoring is ignored, a score of 0 for all documents is returned.

What is the difference between MUST and SHOULD bool query?
must means: The clause (query) must appear in matching documents. These clauses must match, like logical AND.
should means: At least one of these clauses must match, like logical OR.

In other words, results will have to be matched by all the queries present in the must clause or match at least one of the should clauses if there is no must clause.

What is the difference between MUST and FILTER bool query?
The must contributes to the score. In filter, the score of the query is ignored.

In both must and filter, the clause(query) must appear in matching documents. This is the reason for getting same result.

Examples:
To get list of all the bank accounts, execute:
GET bank/account/_search

To get all the bank acconuts from California (State will be CA):
GET bank/account/_search
{
  "query": {
    "match": {"state": "CA"}
  }
}

To get all the bank acconuts of Techade from California (State will be CA)
GET bank/account/_search
{
  "query": {
    "bool": {
      "must": [
        { "match": {"state": "CA"} },
        { "match": {"employer": "Techade"}}
      ]
    }
  }
}

To get all the bank acconuts not from Techade and outside California (State will be CA)
GET bank/account/_search
{
  "query": {
    "bool": {
      "must_not": [
        { "match": {"state": "CA"} },
        { "match": {"employer": "Techade"}}
      ]
    }
  }
}

-K Himaanshu Shuklaa..

Part 5: Elastic Search Interview Questions And Answers(Hands On)

How to check health of cluster and node?
Start ElasticSearch and Kibana, and then open Kibana dashboard (you can open it with this URL  http://localhost:5601/app/kibana#/dev_tools/console)

to check health of cluster execute:
GET _cat/health?v

April 16, 2020

Part 4: Elastic Search Interview Questions And Answers

What is ELK Stack and its contents?
Enterprises, large or small nowadays come across information in the form of reports, data and customer follow-ups and historical, current orders as well as customer reviews from the online and offline logs. It is essential to store and analyze these logs which will help predict valuable feedback for the businesses.

Part 3: Elastic Search Interview Questions And Answers

What is an Elasticsearch Analyzer? What are the various types of analyzers in Elasticsearch?
Analyzers are used for Text analysis, it can be either built-in analyzer or custom analyzer.

The analyzer consists of zero or more character filters, at least one Tokenizer and zero or more Token filters.

Part 2: Elastic Search Interview Questions And Answers

Explain the procedure to add or create an index in Elasticsearch Cluster?
To add a new index, create an index API option should be used. The parameters required to create the index is Configuration setting of an index, Fields mapping in the index as well as Index aliases.

Part 1: Elastic Search Interview Questions And Answers

Explain in brief about Elasticsearch?
Elasticsearch is an open-source, RESTful, scalable, built on Apache Lucene library, document-based search engine. It stores retrieve and manage textual, numerical, geospatial, structured and unstructured data in the form of JSON documents using CRUD REST API or ingestion tools such as Logstash.

July 01, 2019

CAP Theorem

CAP theorem (also known as Eric Brewers theorem) states that we can only achieve at most two out of three guarantees for a database: Consistency, Availability and Partition Tolerance.

August 03, 2018

Delete, Drop and Truncate

What is the difference between Delete and Truncate commands.
Delete and truncate both commands can be used to delete data of the table.

e.g:
//Truncate Query
TRUNCATE TABLE table_name;

//Delete Query
DELETE FROM table_name WHERE < condition > ;

July 02, 2018

Difference between RANK, DENSE_RANK and ROW_NUMBER functions

RANK
The RANK function is used to retrieve ranked rows based on the condition of the ORDER BY clause. For example, if you want to find the name of the employee with third highest salary, you can use RANK Function.

May 07, 2018

SQL Interview Questions And Answers

What is SQL?
SQL (Structured Query Language) is a standardized programming language used for managing relational databases and performing various operations like creation, deletion, fetching rows and modifying on the data in them.

July 01, 2017

Correlated Subqueries

A correlated subquery is a subquery that uses the values of the outer query, i.e it depends on the outer query for its values. Because of this dependency, a correlated subquery cannot be executed independently as a simple subquery.

July 01, 2016

ACID properties in DBMS

ACID properties provide a mechanism to ensure correctness and consistency of a database in a way such that each transaction is a group of operations that acts a single unit, produces consistent results, acts in isolation from other operations and updates that it makes are durably stored.

Atomicity
The atomicity means either all the operations (insert, update, delete) inside a transaction take place or none. Or you can say, all the statements (insert, update, delete) inside a transaction are either completed or rolled back. There is no midway i.e. transactions do not occur partially. Atomicity is also known as the ‘All or nothing rule’.

March 01, 2016

Difference between Stored Procedure and Function?

Stored Procedure
  • It is a precompiled set of one or more SQL statements that is stored on Sql Server.
  • As Stored Procedures are executed on the server side and perform a set of actions, before returning the results to the client side, which allows a set of actions to be executed with minimum time and also reduce the network traffic. Hence stored procedure improve performance to execute sql statements.
  • Stored procedure can accepts input and output parameters.
  • Stored procedure can returns multiple values using output parameters.
  • Using stored procedure, we can Select, Insert, Update or Delete data in database.

June 16, 2014

Database Joins example!

CREATE TABLE employee
(employeeid int(10) default NULL,
employeefname varchar(12) default NULL,
employeelname varchar(12) default NULL,
CONSTRAINT employeeid PRIMARY KEY (employeeid));