SelfMadeSQL
SelfMadeSQL
2. What is DBMS?
A special software program that helps users to create and maintain database.
Makes it easy to manage large amount of information.
Handles security
Backups
Importing/exporting data
Concurrency
Interacts with software applications
Relational Database
Relational Database Management System(RDBMS)
Helps user to create and maintain a relational database.
MySQL
Oracle
PostreSQL etc
5. What is SQL?
SQL is a language used for interacting with relational database management
system(RDBMS).
You can use SQL to get the RDBMS to do things for you.
Create, delete, update data.
Design and create database tables.
Perform administration tasks.
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)
);
1 99586465 2
2 78466588 2
3 22354846 3
4 57698656 1
Q10.What is Super Key?
A superkey is a combination of columns that uniquely identifies any row within a
relational database management system (RDBMS) table.
Composite Key: A composite key, also known as a compound key, is a key that
consists of two or more columns to uniquely identify a row in a table. It's useful
when a single column doesn't provide enough uniqueness.
Unique Key: Similar to a primary key, a unique key constraint ensures that all
values in the key column(s) are unique, but unlike a primary key, it allows for null
values (except in SQL Server). A table can have multiple unique keys.
Suppose we want to store the data and we don’t have the one column value major
Q20. What is a Join? List its different types.
In SQL, joins are used to combine rows from two or more tables based on
a related column between them. Joins allow you to retrieve data from
multiple tables.
1. inner join,
2. left outer join,
3. right outer join,
4. full outer join, and
5. cross join.
1. INNER JOIN: Returns only the rows that have matching values
in both tables based on the specified join condition.
Who saara data milta hai, jo left table me hai or woh agar match karta hai
right table se………Jo table pehele likhenege who left table ban jaayegi or
dusri right table
FULL JOIN = A FULL JOIN in SQL is a type of join operation that
combines the results of both a LEFT JOIN and a RIGHT JOIN. It returns all
records when there is a match in either the left or right table. If there is no
match, NULL values are returned for the columns from the table that lacks a
matching row.
12. What is a Self-Join?
Jb ap same table me, different columns ko join karte ho.
Ek hi table ke name ko 2 baar likhte hain
MINUS (or EXCEPT): The MINUS operator, often called EXCEPT in some
database systems, is used to retrieve the rows from the first SELECT
statement that are not present in the result set of the second SELECT
statement. It is similar to the set difference operation in mathematics.
Example:
INTERSECT: The INTERSECT operator is used to retrieve the rows that
appear in both result sets of the SELECT statements. It returns only
distinct rows that are common to both SELECT statements.
Example:
14. What is an Index? Explain its different types.
A database index is a data structure that provides a quick lookup of data in a column or columns of a
table. It enhances the speed of operations accessing data from a database table at the cost of
additional writes and memory to maintain the index data structure.
3.because joins ke sath jo data milta hai kaafi lengthy hota hai toh isliye mostly joins ke liye
hm index laga dete hain.
Index create karne ke bad time kam hogya upper wali query ka.
OUTPUT 8
2.
OUTPUT5
3.
OUTPUT4
2.Sum()
The MySQL sum() function is used to return the total summed value of an
expression. It returns NULL if the result set does not have any rows.
3.MySQL avg() function
1.WHERE
It filters the records. It returns only those queries which fulfill the specific
conditions..
= equal
3. GROUP BY clause in SQL is used to group records with identical data and can be used in
conjunction with some aggregation functions to produce summarized results from the database.
6.HAVING clause in SQL is used to filter records in combination with the GROUP BY clause.
It is different from WHERE, since the WHERE clause cannot filter aggregated records.
RESULT= IT
Group by ke sath WHERE clause kaam nhi karta bcz WHERE Clause puri table ke liye kaam
karta hai ….or humne GROUP BY laga kar table ko groups me divide kar diya hai.
Also print the name of the employee
Result = varun
1. Creating view
2. Creating View from a single table
OUTPUT
3.
NAME
In isliye use kiya becoz hm kisi ek particular row se compare nhi kar rahe hai,
IN/NOT IN
Jb bhi hmre pass comparison ke liye ek taraf 2 ya 2 se Jayada values toh IN use karte hai.
EXIST/ NOT EXIST