SQL

SQL (Structured Query Language) is used to perform operations on the records stored in the database such as creating records, updating records, deleting records and modifying tables, views, etc.

SQL is just a query language: SQL is not a database. To perform SQL queries, we need to install any database, for example, Oracle, MySQL, MongoDB, PostGre SQL, SQL Server, DB2, etc.

In general SQL is required :

  1. To create new databases, tables and views
  2. To insert records in a database
  3. To update records in a database
  4. To delete records from a database
  5. To retrieve data from a database

What is DBMS?

ANS) A Database Management System (DBMS) is a program that controls creation, maintenance and use of a database. DBMS can be termed as File Manager that manages data in a database rather than saving it in file systems.

There is no place where Data does not exist! In today’s market, around 2.5 Quintilian bytes of data gets generated every day. So, it is very important for all of us to analyze this data and generate the required results. But, before that, we have to handle databases using the database management systems(DBMS).

What is RDBMS?

ANS) RDBMS stands for Relational Database Management System. RDBMS store the data into the collection of tables, which is related by common fields between the columns of the table. It also provides relational operators to manipulate the data stored into the tables.

What is a Database?

ANS) Database is nothing but an organized form of data for easy access, storing, retrieval and managing of data. This is also known as structured form of data which can be accessed in many ways.

Example: School Management Database, Bank Management Database.

What are the ACID properties in DBMS?

ANS) ACID stands for Atomicity, Consistency, Isolation and Durability. It is used to ensure that the data transactions are processed reliably in a database system. 

  1. Atomicity: Atomicity refers to those transactions which are completely successful or failed. Here each transaction refers to a single logical operation of a data. So, even if one part of any transaction fails, the entire transaction fails and the database state is left unchanged.
  2. Consistency: Consistency ensures that the data must meet all the validation rules. In simple words,  you can say that your transaction never leaves the database without completing its state.
  3. Isolation: The main goal of isolation is concurrency control.
  4. Durability: Durability means that if a transaction has been committed, it will occur whatever may be the scenario.

What are tables and Fields?

ANS) A table is a set of data that are organized in a model with Columns and Rows. Columns can be categorized as vertical, and Rows are horizontal. A table has specified number of column called fields but can have any number of rows which is called record.

What is a primary key?

ANS) A primary key is a combination of fields which uniquely specify a row. This is a special kind of unique key, and it has implicit NOT NULL constraint. It means, Primary key values cannot be NULL.

What is a unique key?

ANS) A Unique key constraint uniquely identified each record in the database. This provides uniqueness for the column or set of columns.

A Primary key constraint has automatic unique constraint defined on it. But not, in the case of Unique Key.

There can be many unique constraint defined per table, but only one Primary key constraint defined per table.

What is a foreign key?

ANS) A foreign key is one table which can be related to the primary key of another table. Relationship needs to be created between two tables by referencing foreign key with the primary key of another table.

What is a join?

ANS) This is a keyword used to query data from more tables based on the relationship between the fields of the tables. Keys play a major role when JOINs are used.

What are joins in SQL and what are the different types of joins?

ANS) JOIN clause is used to combine rows from two or more tables, based on a related column between them. It is used to merge two tables or retrieve data from there. 

There are various types of join which can be used to retrieve data and it depends on the relationship between tables.There are 4 joins in SQL namely: 

  1. Inner Join: Inner join return rows when there is at least one match of rows between the tables.
  2. Right Join: Right join return rows which are common between the tables and all rows of Right hand side table. Simply, it returns all the rows from the right hand side table even though there are no matches in the left hand side table.
  3. Left Join: Left join return rows which are common between the tables and all rows of Left hand side table. Simply, it returns all the rows from Left hand side table even though there are no matches in the Right hand side table.
  4. Full Join: Full join return rows when there are matching rows in any one of the tables. This means, it returns all the rows from the left hand side table and all the rows from the right hand side table.

What is normalization?

ANS) Normalization is the process of minimizing redundancy and dependency by organizing fields and table of a database. The main aim of Normalization is to add, delete or modify field that can be made in a single table.

What is Denormalization.

ANS) DeNormalization is a technique used to access the data from higher to lower normal forms of database. It is also process of introducing redundancy into a table by incorporating data from the related tables.

 What are all the different normalizations?

ANS) The normal forms can be divided into 5 forms, and they are explained below -.

  1. First Normal Form (1NF): This should remove all the duplicate columns from the table. Creation of tables for the related data and identification of unique columns.
  2. Second Normal Form (2NF): Meeting all requirements of the first normal form. Placing the subsets of data in separate tables and Creation of relationships between the tables using primary keys.
  3. Third Normal Form (3NF): This should meet all requirements of 2NF. Removing the columns which are not dependent on primary key constraints.
  4. Fourth Normal Form (4NF): Meeting all the requirements of third normal form and it should not have multi- valued dependencies.

What is a View?

ANS) A view is a virtual table which consists of a subset of data contained in a table. Views are not virtually present, and it takes less space to store. View can have data of one or more tables combined, and it is depending on the relationship.

What is an Index?

ANS) An index is performance tuning method of allowing faster retrieval of records from the table. An index creates an entry for each value and it will be faster to retrieve data.

What are all the different types of indexes?

ANS) There are three types of indexes -.

  • Unique Index : This indexing does not allow the field to have duplicate values if the column is unique indexed. Unique index can be applied automatically when primary key is defined.
  • Clustered Index : This type of index reorders the physical order of the table and search based on the key values. Each table can have only one clustered index.
  • NonClustered Index: NonClustered Index does not alter the physical order of the table and maintains logical order of data. Each table can have 999 nonclustered indexes.
 

What is a relationship and what are they?

ANS) Database Relationship is defined as the connection between the tables in a database. There are various data basing relationships, and they are as follows:.

  1. One to One Relationship.
  2. One to Many Relationship.
  3. Many to One Relationship.
  4. Self-Referencing Relationship.
What is a Cursor?

ANS) A database Cursor is a control which enables traversal over the rows or records in the table. This can be viewed as a pointer to one row in a set of rows. Cursor is very much useful for traversing such as retrieval, addition and removal of database records.

Explain about sql constraints?

ANS) Constraints:

A constraint is a condition which restricts the invalid data in the table.
A constraint can be provided for a column of a table.

We have below types of Constraints in SQL:
  1. NOT NULL
  2. UNIQUE
  3. Primary Key
  4. Foreign Key
  5. Check
NULL:
  •  NULL is nothing, it is neither zero nor blank space
  •  It will not occupy any space in the memory
  •  Two nulls are never same in Oracle
  •  NULL represents unknown value
  • Any arithmetic operation we perform on NULL will result in NULL itself.
NOT NULL:
  • NOT NULL will ensure at least some value should be present in the column
UNIQUE:
  • It will not allow any duplicates in a column
  • UNIQUE column can take only one NULL.
Primary Key:
  • It is the combination of NOT NULL and UNIQUE
  • Only one Primary Key is allowed in one table
  • Primary Key identifies a record uniquely in a table
  • Creation of Primary Key is not mandatory, but it is highly recommended to create
Foreign Key:
  • Foreign Key creates relationship between any two tables
  • FK is also called as referential integrity constraint
  • FK is created on the child table
  • FK can take both NULL and duplicate values
  • To create FK, the Master table should have PK defined on the common column of the master table
  • We can have more than one FK in a given table
CHECK:
  • It is used to provide additional validations as per the customer requirements.



No comments:

Post a Comment

Hello Buddy, if you have any doubts or need any clarification , feel free to comment. Thanks.