Q1. What is a 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 modern approaches.
Q2. What is DBMS ?
DBMS Stands for Database management System. DBMS is a system software that is responsible for the creation, retrieval and 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 end-users or application software.
Q3. What is RDBMS ? How it is different from DBMS ?
RDBMS Stands for Relational Database Management System. The key difference here, compared to DBMS, is that RDBMS stored data in the form of a collection of tables, and relation 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.
Q4. What is SQL ?
SQL Stands for Structured Query Language, and it is used to access the Database. This is a standard language used to perform tasks such as retrieval, updation, insertion and deletion of data from a Database.
Q5. 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.
Q6. 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 tables while the rows can be referred to as records.
Example:
Table: Employee
Field: Emp ID, Emp Name, Date of Birth.
Data: 201576, Karthik, 11/12/1989
Q7. 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 a SQL table during the creation of the table or after using the ALTER TABLE Command. The Constraints are :
- NOT NULL - Restricts NULL values 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.
The PRIMARY KEY constraints 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 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);
Q9. What is a UNIQUE constraint ?
A UNIQUE constraint ensures that all values in a column are different. This provides uniqueness for the columns and helps to identify each row uniquely. Unlike primary key, there 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);
Q10. 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 the two tables.
The table with the foreign key constraint is labeled as a 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);
Q11. What are the different types of statements ?
(a) DDL (Data Definition Language) : it is used to define the database structure such as tables. It includes three statements such as CREATE, ALTER, and DROP.
Some of the DDL Commands are listed below :
CREATE: It is used to create the table
CREATE
TABLE
table_name
column_name1 data_type(
size
),
column_name2 data_type(
size
),
column_name3 data_type(
size
),
ALTER: The ALTER table is used for modifying the existing table object in the database.
ALTER
TABLE
table_name
ADD
column_name datatype
OR
ALTER
TABLE
table_name
DROP
COLUMN
column_name
(b) DML (Data Manipulation Language): These statements are used to manipulate the data in records.
Commonly used DML statements are INSERT, UPDATE and DELETE.
The SELECT statement is used as a partial DML statement, used to select all or relevant records in the table.
(c) DCL (Data Control Language): These statements are used to set privileges such as GRANT and REVOKE
database access permission to the specific user.
Q12. What are the different clauses used in SQL ?
WHERE Clause: This clause is used to define the condition, extract and display only those records which fulfill
the given condition
Syntax:
SELECT column_name(s) FROM table_name WHERE condition;
GROUP Clause: It is used with SELECT statement to group the result of the executed query using the value specified in it. It matches the value with the column name in tables and groups the end result accordingly. Syntax:
4 Major types are used while working on multiple joins in SQL databases: INNER JOIN: It is also known as SIMPLE JOIN which returns all rows from both tables when it has at least one matching column Syntax: SELECT column_name(s) FROM table_name1 INNER JOIN table_name2 ON column_name1=column_name2;
LEFT JOIN(LEFT OUTER JOIN): This JOIN returns all rows from the LEFT table and its matched rows from a RIGHT table. Syntax: SELECT column_name(s) FROM table_name1 LEFT JOIN table_name2 ON column_name1=column_name2;
SELECT column_name(s) FROM table_name1 RIGHT JOIN table_name2 ON column_name1=column_name2;
SELECT column_name(s) FROM table_name1 FULL OUTER JOIN table_name2 ON column_name1=column_name2;
Scalar functions are used to return a single value based on the input values. Scalar functions are as follows:
Triggers in SQL is kind of stored procedure used to create a response to a specific action performed on the table such as INSERT, UPDATE or DELETE. You can invoke triggers explicitly on the table in the database. Action and event are two components of SQL triggers. When certain actions are performed, the event occurs in response to that action. Syntax:
|
Nice blog
ReplyDeleteNice one!
ReplyDeleteGood
ReplyDeleteGood
ReplyDeleteThank you for your support and please share and comments other posts also
Delete