0% found this document useful (0 votes)
6 views

SQL

SQL (Structured Query Language) is a specialized language for managing and manipulating databases, allowing users to perform operations such as creating, reading, updating, and deleting data. Databases can be relational, organized into tables with defined relationships, or non-relational, stored in a tree format. SQL supports various operations and commands, including CRUD operations, data types, and joins, to efficiently manage and query data.

Uploaded by

vasajagadishwar1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

SQL

SQL (Structured Query Language) is a specialized language for managing and manipulating databases, allowing users to perform operations such as creating, reading, updating, and deleting data. Databases can be relational, organized into tables with defined relationships, or non-relational, stored in a tree format. SQL supports various operations and commands, including CRUD operations, data types, and joins, to efficiently manage and query data.

Uploaded by

vasajagadishwar1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 9

SQL - Structered query language

* A special language which is used for talking to and working with databases.Its like an set of instructions that helps you ask qu
Data - Data is raw,unprocessed facts,figures or information.
Database - A database is a structered collection of organized data used for efficient storage,retrieval and management.
Eg : In mobile contacts can be either saved internal or external but ultimately saved in mobile itself
Types of Database
Relational Database (RDBMS)
* A structered system for storing and managing data organized into tables with defined relationships.
Eg : Relation database is used for common column which is used to fetch the value needed,Also it is used to join the table kno
Register table
Roll No Name Branch
1 Uday CSE
2 Raj ECE
3 Kiran CIVIL

Fee table
Roll No Fee due
1 300
2 5000
3 150

Non Relational Database


* It is saved in as tree format
* It does not uses a traditional tabular relational model to organize data
CRUD OPERATIONS
Create : It is used for creating a database or table
Read : It is used to extract the data or analyzing.
Update : It is used for update the data in database
Delete: It is used to delete the information
Data types
INT (Integer) : AGE 18
FLOAT (Floating Point) : HEIGHT 5.6
CHAR (FIXED LENGTH CHARACTER) : NAME ESHWAR
VARCHAR (Variable - Length Character): ADDRESS 1-56,HYD
DATE : DOB 01-01-1950
TIME: BREAK 09:00AM
BOOLEAN: INDIAN..? True
BINARY INDIAN..? 1
h databases.Its like an set of instructions that helps you ask questions about the data in a database,make changes to it or organize in a diff

a used for efficient storage,retrieval and management.


ut ultimately saved in mobile itself

nto tables with defined relationships.


to fetch the value needed,Also it is used to join the table known as relational database.

Section
A
B
A

* No values can represented as - or Null


* Use- it is the keyword used for ACTIVATION
* Sum - Adding total numbers
* Key words will represent in blue colour,Normal words will represent in black.
* symbol represents data
* INT does not required inverted commas
*VARCHAR and Char should be in inverted commas" "
*Insert in to name values should be written Eg: INSERT INTO VALUES
*INT - Not required to specify
*Char 50
*Varchar length 255
*Semicolon ; - It is used to consider the code, after semicolon it does not consider any code
* Flash button is used for running codes
Amost 95% used to write codes in below
SELECT: To retreive data from a Database
FROM: Specifies the table or source from which data is selected
WHERE: Selecting Specific rows from a dataset based on defined criteria or conditions. Eg SE
Sorting - ORDER BY: Arranging query results in a specific order Eg : ORDER BY NAME; this is Ascending o
GROUPING-GROUP BY: Group rows with similar values in specified columns,Coverting two rows into single
AGGREGATE FUNTIONS : Performing calculations on data to get the summarized data
MINIMUM Min Value
MAXIMUM Max Value
COUNT Counts (FIRSTNAME)(USERNAME)
TOTAL Adding total values
AVERAGE Avg total value
HAVING Used to filter grouped data results based on conditions after using the "GROUP BY"
Interview question WHERE VS HAVING
* Where can be used in normal queries where posts greater or less than.
* Having can be used in aggregate functions.
hanges to it or organize in a different ways.

ned criteria or conditions. Eg SELECT * FROM ……(TABLE NAME) WHERE …(No of values)>…;(Semicolon)
R BY NAME; this is Ascending order, ORDER BY NAME; DESC; this is descending order[By default it takes ascending order)
Coverting two rows into single row

ons after using the "GROUP BY" [MORE THAN 2 USERS FROM A COUNTRY],Having can used when aggregate funtions are used.
ending order)

funtions are used.


SQL CODE
*CREATE DATA ….(NAME);
* USE …(NAME);
* CREATE TABLE …(NAME)(USERNAME VARCHAR(255), FIRSTNAME CHAR(50), POSTS INT, COUNTRY CHAR(50)
* SELECT * FROM..(NAME);
*INSERT INTO ACCOUNTS VALUES("_eshwar123","eshwar",5,"India");

Different types ofCombining data from two or more tables based on related columns
Inner join Returns only the rows where there is a match in both tables joined, 1st it fetches the c
left join Returns all rows from the left table and the matched rows from right table,When there is
Right join Returns all rows from the Right table and the matched rows from left table,When there is
union
full join SELECT * FROM ACCOUNTS right JOIN LIKES1 ON ACCOUNTS.USERNAME= likes1.USERNAME;

Set Operators anColumns


UNION should be equal or same
UNION SELECT * FROM ACCOUNTS WHERE POSTS = 25;
UNION ALL
UNION ALL SELECT * FROM ACCOUNTS WHERE POSTS = 99;
INTERSECT it fetches only the same values,output will be the common values.
EXCEPT/MINUS 1st It fetches only common values and it removes,If there is any duplicate values output will b

Sub queries Query embedded with another query


*SELECT (SELECT USERNAME FROM LIKES WHERE LIKES.USERNAME = ACCOUNTS.USERNAME)
FROM ACCOUNTS
WHERE POSTS = 99;
DDL[Data DefinatDML[DATA MADCL[DATA TCL[TRANSACDQL[DATA QUERY LANGUAGE]
CREATE INSERT GRANT COMMIT SELECT
ALTER UPDATE REVOKE ROLLBACK
DROP DELETE SAVE POINT
TRUNCATE
* GRANT Giving access
* REVOKE Removing access
* UPDATE Updating the date in DATABASE
* CREATE Creating database and creating tables
* INSERT Inserting values in to tables
* ALTER Used to modify the structure of an existing table in a database ADD COLUMN,MODIFY COLUMN, DROP COLU
* COMMIT When transcation is successful
* ROLLBACK When transcation fails it rollsback or message appears
* SAVEPOINT It saves when transaction debit on one end and credit on other end
* SELECT To retreive data from database
LIKE SEARCH ANY RELATED PRODUCT USING %WORD%,"_j%"represents one character,[] used to find multiple c
OR, IN It is used for using multiple sets in single
Between or extract Between or extract
ROUNDED Float to number (near integer)
AS Alias,If you are using space between two words keep bracketes
TO CHAR It is used for extracting date format
UPPER KEY SELECT (KEYWORD) FROM TABLENAME
LOWER KEY SELECT (KEYWORD) FROM TABLENAME
EXTRACT YEAR_MONTH FROM DATE
IDENTITY Auto increment like 1,2,3,4
GROUP BY In group by having only works,where cannot works
WHERE It can be VARCHAR(255)
COURSE used with AND,OR,NOT
*UNIQUE KEY );
COURSEID INT PRIMARY KEY
* FOREIGN KEY );
insert INTO STUDENTS VALUES (01,"RAJ","CSE");
* DESCRIBE SELECT
COURSE*VARCHAR(255)
FROM STUDENTS;
* PRIMARY KEY );
Privalages = Permissions
*.* = DATABASE.TABLE
* identified by is used to specify the password
* Gives conditions only for primary keys
* Set is a function used to update
DDL[Data definationDefines and Manages the structures of databases,Including creating,altering and droping, database object
ALTER
ADD COLUMN Adding the extra column Eg ALTER TABLE COURSE ADD COLUMN PROFESSER CHAR(55);
MODIFY COLUMN Eg: Modify the column char into varchar Eg ALTER TABLE COURSES MODIFY BRANCH VARCHAR(255);
DROP COLUMN Deleting entire column permanently eg ALTER TABLE COURSE drop PROFESSER; [Gets deleted permanentl
RENAME COLUMN Changing one column name into other Eg ALTER TABLE COURSE rename column BRANCH to COURSE;
DROP Used to remove the existing table or all other data eg DROP TABLE COURSE;
TRUNCATE Used to quickly delete all rows from a table while maintaing the table structure,it delete only the rows valu
DML[DATA MANUPU Facilitates the manupulation of data within the database including operations such as
INSERT Inserting values in to tables
UPDATE Used to modify existing records in a table Eg UPDATE ……[NAME] SET COURSE = "AIML" WHERE ID = J01;
DELETE Used to remove an entire table or row from a database with conditions Eg DELETE ….[FROM] COURSES WH
ODIFY COLUMN, DROP COLUMN, RENAME COLUMN
DCL [DATA CONTROControl
CREATE access to data within database
USER UDAY@localhost Such
identified by as GRANT AND REVOKE,Managing permissions and security fu
"1234567890";
GRANT GRANT ALL privileges on *.* TO UDAY@localhost;
REVOKE Used to revoke previously granted privileges or permissions on database objects from users Eg REVOKE AL
TCL[TRANSACTION INSERT
Manages the EXAMS
INTO transactions within a database including commands like COMMIT,ROLLBACK AND SAVEPOIN
VALUES(1,"REG",810);
COMMIT commit;
INSERT INTO EXAMS VALUES("_J004","REG",0);
ROLLBACK rollback;
rollback to B;
SAVEPOINT commit;
DQL[DATA QUERY LUsed to manage and manipulate relational databases,allowing users to query data using commands like SE
SELECT To retreive data from a database
aracter,[] used to find multiple characters like "[JM]%",^ represents not syntax "[^JM]%"

ng and droping, database objects such as tables,views and index.

ER CHAR(55);
RANCH VARCHAR(255);
SSER; [Gets deleted permanently in database including trash]
olumn BRANCH to COURSE;

cture,it delete only the rows values,columns will remain the same Eg TRUNCATE TABLE COURSES;
ons such as

RSE = "AIML" WHERE ID = J01;


DELETE ….[FROM] COURSES WHERE ID = "C04";

ging permissions and security functions.

bjects from users Eg REVOKE ALL privileges ON *.* FROM Eshwar@localhost;


MMIT,ROLLBACK AND SAVEPOINT to ensure data consistency and integrity.

ery data using commands like SELECT,JOIN,WHERE and GROUPBY


DATA_ADD [Column name, Interval 1month,1year,1hour]
TOP10 GETS TOP10 Data from particular column
GROUPBY,HAWe can remove duplicate values by using those keyword functions

You might also like