0% found this document useful (0 votes)
2 views3 pages

SQL Functions and Syntax Guide

This document is a quick revision sheet for SQL functions and syntax, categorized into aggregate, string, numeric, date & time, conversion, clauses, DDL, DML, DCL, and TCL functions. Each category includes examples of common SQL commands. It serves as a concise reference for SQL operations and their usage.

Uploaded by

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

SQL Functions and Syntax Guide

This document is a quick revision sheet for SQL functions and syntax, categorized into aggregate, string, numeric, date & time, conversion, clauses, DDL, DML, DCL, and TCL functions. Each category includes examples of common SQL commands. It serves as a concise reference for SQL operations and their usage.

Uploaded by

aakeapubgmobile
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SQL Functions & Syntax - Quick Revision Sheet

Aggregate Functions
Function Example

COUNT() SELECT COUNT(*) FROM student;


SUM() SELECT SUM(marks) FROM student;
AVG() SELECT AVG(marks) FROM student;
MIN() SELECT MIN(marks) FROM student;
MAX() SELECT MAX(marks) FROM student;

String Functions
Function Example

UPPER() SELECT UPPER(name) FROM student;


LOWER() SELECT LOWER(city) FROM student;
LENGTH() SELECT LENGTH(name) FROM student;
SUBSTRING() SELECT SUBSTRING(name,1,3) FROM student;
CONCAT() SELECT CONCAT(name,'-',city) FROM student;
TRIM() SELECT TRIM(' Hello ');

Numeric Functions
Function Example

ROUND() SELECT ROUND(92.567,2);


FLOOR() SELECT FLOOR(92.9);
CEIL() SELECT CEIL(92.1);
POWER() SELECT POWER(2,3);
ABS() SELECT ABS(-45);

Date & Time Functions


Function Example

NOW() SELECT NOW();


CURDATE() SELECT CURDATE();
CURTIME() SELECT CURTIME();
DAY() SELECT DAY(dob) FROM student;
MONTH() SELECT MONTH(dob) FROM student;
YEAR() SELECT YEAR(dob) FROM student;

Conversion Functions
Function Example

CAST() SELECT CAST(85.9 AS INT);


CONVERT() SELECT CONVERT('2025-08-17', DATE);

Clauses
Function Example

SELECT SELECT name, marks FROM student;


WHERE SELECT * FROM student WHERE marks>80;
DISTINCT SELECT DISTINCT city FROM student;
ORDER BY SELECT * FROM student ORDER BY marks DESC;
GROUP BY SELECT city, COUNT(*) FROM student GROUP BY city;
HAVING SELECT city, COUNT(*) FROM student GROUP BY city HAVING COUNT(*)>1;
LIMIT SELECT * FROM student LIMIT 3;

DDL (Definition)
Function Example

CREATE CREATE TABLE student(id INT, name VARCHAR(50));


ALTER ALTER TABLE student ADD grade CHAR(1);
DROP DROP TABLE student;
TRUNCATE TRUNCATE TABLE student;

DML (Manipulation)
Function Example

INSERT INSERT INTO student VALUES(6,'Kiran','Pune',70,'2005-09-15');


UPDATE UPDATE student SET marks=95 WHERE id=1;
DELETE DELETE FROM student WHERE id=3;

DCL (Control)
Function Example

GRANT GRANT SELECT ON student TO user1;


REVOKE REVOKE SELECT ON student FROM user1;

TCL (Transactions)
Function Example

COMMIT COMMIT;
ROLLBACK ROLLBACK;
SAVEPOINT SAVEPOINT sp1;

You might also like