Question:- What is denormalization?
Answer:- Denormalization is the opposite of normalization; redundant data is added to speed up complex queries that have multiple tables that need to be joined. Optimization of the read performance of a database is attempted by adding or grouping redundant copies of data.
Question:- What are Joins in SQL?
Answer:- Join in SQL is used to combine rows from two or more tables based on a related column between them. There are various types of Joins that can be used to retrieve data, and it depends on the relationship between tables. There are four types of Joins: • Inner Join • Left Join • Right Join • Full Join
Question:- Explain the types of SQL joins.
Answer:- There are four different types of SQL Joins: • (Inner) Join: It is used to retrieve the records that have matching values in both the tables that are involved in the join. Inner Join is mostly used to join queries. • Left (Outer) Join: Use of left join is to retrieve all the records or rows from the left and the matched ones from the right. • Right (Outer) Join: Use of Right join is to retrieve all the records or rows from the right and the matched ones from the left. • Full (Outer) Join: The use of Full join is to retrieve the records that have a match either in the left table or the right table.
Question:- What are the subsets of SQL?
Answer:- SQL queries are divided into four main categories: • Data Definition Language (DDL) DDL queries are made up of SQL commands that can be used to define the structure of the database and modify it. • CREATE Creates databases, tables, schema, etc. • DROP: Drops tables and other database objects • DROP COLUMN: Drops a column from any table structure • ALTER: Alters the definition of database objects • TRUNCATE: Removes tables, views, procedures, and other database objects • ADD COLUMN: Adds any column to the table schema • Data Manipulation Language (DML) These SQL queries are used to manipulate data in a database. • SELECT INTO: Selects data from one table and inserts it into another • INSERT: Inserts data or records into a table • UPDATE: Updates the value of any record in the database • DELETE: Deletes records from a table • Data Control Language (DCL) These SQL queries manage the access rights and permission control of the database. • GRANT: Grants access rights to database objects • REVOKE: Withdraws permission from database objects • Transaction Control Language (TCL) TCL is a set of commands that essentially manages the transactions in a database and the changes made by the DML statements. TCL allows statements to be grouped together into logical transactions. • COMMIT: Commits an irreversible transaction, i.e., the previous image of the database prior to the transaction cannot be retrieved • ROLLBACK: Reverts the steps in a transaction in case of an error • SAVEPOINT: Sets a savepoint in the transaction to which rollback can be executed • SET TRANSACTION: Sets the characteristics of the transaction
Question:- What are the applications of SQL?
Answer:- The major applications of SQL include: • Writing data integration scripts • Setting and running analytical queries • Retrieving subsets of information within a database for analytics applications and transaction processing • Adding, updating, and deleting rows and columns of data in a database
Question:- What is a DEFAULT constraint?
Answer:- Constraints in SQL are used to specify some sort of rules for processing data and limiting the type of data that can go into a table. Now, let us understand what is a default constraint. A default constraint is used to define a default value for a column so that it is added to all new records if no other value is specified. For example, if we assign a default constraint for the E_salary column in the following table and set the default value to 85000, then all the entries of this column will have the default value of 85000, unless no other value has been assigned during the insertion.
Question:- What is a UNIQUE constraint?
Answer:- Unique constraints ensure that all the values in a column are different. For example, if we assign a unique constraint to the e_name column in the following table, then every entry in this column should have a unique value. First, we will create a table. create table stu2(s_id int unique, s_name varchar(20)) Now, we will insert the records. insert into stu2 values(1,’Julia’) insert into stu2 values(2,’Matt’) insert into stu2 values(3,’Anne’) A PRIMARY KEY constraint will automatically have a UNIQUE constraint. However, unlike a PRIMARY KEY, multiple UNIQUE constraints are allowed per table.
Question:- What is meant by table and field in SQL?
Answer:- An organized data in the form of rows and columns is said to be a table. Simply put, it is a collection of related data in a table format. Here rows and columns are referred to as tuples and attributes, and the number of columns in a table is referred to as a field. In the record, fields represent the characteristics and attributes and contain specific information about the data.
Question:- What is a primary key?
Answer:- A primary key is used to uniquely identify all table records. It cannot have NULL values and must contain unique values. Only one primary key can exist in one table, and it may have single or multiple fields, making it a composite key. Now, we will write a query for demonstrating the use of a primary key for the employee table: // CREATE TABLE Employee ( ID int NOT NULL, Employee_name varchar(255) NOT NULL, Employee_designation varchar(255), Employee_Age int, PRIMARY KEY (ID) );
Question:- What is a unique key?
Answer:- The key that can accept only a null value and cannot accept duplicate values is called a unique key. The role of a unique key is to make sure that all columns and rows are unique. The syntax for a unique key will be the same as the primary key. So, the query using a unique key for the employee table will be: // CREATE TABLE Employee ( ID int NOT NULL, Employee_name varchar(255) NOT NULL, Employee_designation varchar(255), Employee_Age int, UNIQUE(ID) );
Question:- What is the difference between primary key and unique key?
Answer:- Both primary and unique keys carry unique values but a primary key cannot have a null value, while a unique key can. In a table, there cannot be more than one primary key, but there can be multiple unique keys.
Question:- What is a foreign key?
Answer:- A foreign key is an attribute or a set of attributes that reference the primary key of some other table. Basically, a foreign key is used to link together two tables. Let us create a foreign key for the following table: CREATE TABLE Orders ( OrderID int NOT NULL, OrderNumber int NOT NULL, PersonID int, PRIMARY KEY (OrderID), FOREIGN KEY (PersonID) REFERENCES Persons(PersonID) )
Question:- What are the subsets of SQL?
Answer:- The main subsets of SQL are: • Data Definition Language (DDL) • Data Manipulation Language (DML) • Data Control Language (DCL) • Transaction Control Language (TCL)
Question:- Explain the different types of SQL commands.
Answer:- • DDL: DDL is that part of SQL that defines the data structure of the database in the initial stage when the database is about to be created. It is mainly used to create and restructure database objects. Commands in DDL are: • Create table • Alter table • Drop table • DML: DML is used to manipulate already existing data in a database, i.e., it helps users to retrieve and manipulate data. It is used to perform operations such as inserting data into the database through the insert command, updating data with the update command, and deleting data from the database through the delete command. • DCL: DCL is used to control access to the data in the database. DCL commands are normally used to create objects related to user access and to control the distribution of privileges among users. The commands that are used in DCL are Grant and Revoke. • TCL: TCL is used to control the changes made by DML commands. It also authorizes the statements to assemble in conjunction with logical transactions. The commands that are used in TCL are Commit, Rollback, Savepoint, Begin, and Transaction.
