SQL Interview Questions
SQL Interview Questions
What is SQL?
SQL is Structured Query Language. It is standard language used to maintain the relational
database and perform many difficult data manipulation operations on the data. SQL was initially
invented in the year 1970. It is a database language used for database creation, deletion, fetching, and
modifying rows, etc. Sometimes, it is pronounced as ‘SEQUEL’. We can also used it to handle organized
data comprised of entities (variables) and relations between different entities of the data.
SQL was first appeared in 1974. It is one of the most used languages for maintaining the
relational database. In 1986, SQL became the standard of the American National Standards Institute
(ANSI) and International Organization Standardization (ISO) in 1987.
A clustered index is actually a table where data for rows are stored. It determines the order of
the table data based on the key-values that can sort in only one direction. Each table can have only one
clustered index. It is the only index, which has been automatically created when primary key is
generated. If many data modifications needed to be done in the table, then clustered are preferred.
SQL is responsible for maintaining the relational data and the data structures present in the
database, some of the common usage are given below
SQL refers to the Standard Query Language. Therefore it is true that SQL is a language but does
not actually support the programming language. It is a common language that doesn’t have a loop,
conditional statements, and logical operations. It cannot be used for anything other than data
manipulation. The primary purpose of SQL is to retrieve, manipulate, update and perform complex
operations like joins on the data present in the database.
What is the purpose of DDL language?
DDL stands for Data Definition Language. It is the subset of databases that defines the data
structure of the database when the database is created. For Example, we can use the DDL commands to
ass, remove, or modify tables. It consists of the following commands: - CREATE, ALTER and DELETE
database objects such as schema, tables, indexes, views, sequence, etc.
It defines the data structure that consists of commands like CREATE, ALTER, SROP, etc.
It controls access to the data stored in the database. The commands in this category
include GRANT and REVOKE.
It is used to deal with the transaction operations in the database. The commands in this
category are COMMIT, ROLLBACK, SET TRANSACTION, SAVEPOINT, etc.
A primary key is a field or the combination of fields that uniquely identify each round in the
table. It is one of a special kind of unique key. If the column contains a primary key, it cannot be null or
empty. A table can have duplicate columns, but it cannot have more than one primary key. It always
stores unique values into a column.
A table refers to a collection of data in an organized manner in form of rows and columns. A
field refers to the number of columns in a table.
1. NOTNULL
2. CHECK
3. DEFAULT
4. UNIQUE
5. PRIMARY KEY
6. FOREIGN KEY
There are many successive levels of normalization. These are called normal forms. Each
consecutive normal form depends on the previous one. The first three normal forms are usually
adequate.
Triggers in SQL are a special type of stored procedures that are defined to execute automatically
in place or after data modifications. It allows you to execute a batch of code when an INSER or UPDATE
or any other query is executed against a specific table.
The cross join produces the cross product or Cartesian product of two tabled whereas the
natural join is based on all columns have the same name and data types in both the tables.
Group functions work on the set of rows and return on result per group. Some of the commonly
used group functions are – AVG,COUNT, MAX, MIN, SUM, VARIANCE.
You can fetch common records from two tables using INTERSECT.
A stored procedure is a function which consists of many SQL statements to access the database
system. Several SQL statements are consolidated into a stored procedure and execute them whenever
and wherever required, which saves time and avoid writing code again and again
Uniquely identifies a single row in the table. Multiple values allowed per table. Null values
allowed.
What is the difference between CHAR and VARCHAR2 data type in SQL?
Both Char and Varchar2 are used for characters data type but varchar2 is used for characters
string of variable length whereas char is used for strings of fixed length.
Example: - char(10) can store 10 characters and will not be able to store a string of any other length
whereas varchar2(10) can store any length i.e., 6,8,2 in this variable.
SQL MYSQL
SQL is a standard language which stands for MYSQL is a DataBase Management System
Structured Query Language based on the English
language
SQL is the core of the relational database which is MYSQL is an RDBMS (Relational DataBase
used for accessing and managing database. Management System) such as SQL server, Informix,
etc.
Relation or links between entities that have something to do with each other. Relationships are
defined as the connection between the tables in a database. There are various relationships, namely-
1. Unique Index –
This index does not allow the field to have duplicate if the column is unique indexed. It is
a primary key is defined, a unique index can be applied automatically.
2. Clustered Index –
This index records the physical order of the table and searches based on the basis of
key-values. Each table can only have one clustered index.
3. Non- clustered Index –
Non-clustered Index does not alter the physical order of the table and maintains a
logical order of the data. Each table can have many non-clustered indexes.