0% found this document useful (0 votes)
4 views5 pages

CBSE Class12 SQL Commands Syntax

The document provides a comprehensive overview of SQL commands, including Data Definition Language (DDL), Data Manipulation Language (DML), and Data Query Language (DQL) commands with their respective syntax. It also covers constraints, aggregate functions, string functions, numeric functions, date functions, and various operators. Additionally, it lists useful commands and common syntax examples for executing SQL operations.

Uploaded by

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

CBSE Class12 SQL Commands Syntax

The document provides a comprehensive overview of SQL commands, including Data Definition Language (DDL), Data Manipulation Language (DML), and Data Query Language (DQL) commands with their respective syntax. It also covers constraints, aggregate functions, string functions, numeric functions, date functions, and various operators. Additionally, it lists useful commands and common syntax examples for executing SQL operations.

Uploaded by

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

SQL Commands with Syntax

CREATE DATABASE
CREATE DATABASE database_name;

USE DATABASE
USE database_name;

CREATE TABLE
CREATE TABLE table_name (
column1 datatype,
column2 datatype
);

DESC TABLE
DESC table_name;

INSERT
INSERT INTO table_name VALUES (...);

SELECT
SELECT * FROM table_name;

WHERE
SELECT * FROM table_name WHERE condition;

UPDATE
UPDATE table_name SET column=value WHERE condition;

DELETE
DELETE FROM table_name WHERE condition;

ALTER ADD
ALTER TABLE table_name ADD column datatype;

ALTER MODIFY
ALTER TABLE table_name MODIFY column datatype;

ALTER DROP
ALTER TABLE table_name DROP COLUMN column;

DROP TABLE
DROP TABLE table_name;
RENAME
RENAME TABLE old_name TO new_name;

ORDER BY
SELECT * FROM table_name ORDER BY column ASC|DESC;

DISTINCT
SELECT DISTINCT column FROM table_name;

BETWEEN
... WHERE column BETWEEN v1 AND v2;

IN
... WHERE column IN (...);

LIKE
... WHERE column LIKE 'A%';

IS NULL
... WHERE column IS NULL;

IS NOT NULL
... WHERE column IS NOT NULL;

COUNT
SELECT COUNT(*) FROM table_name;

SUM
SELECT SUM(column) FROM table_name;

AVG
SELECT AVG(column) FROM table_name;

MAX
SELECT MAX(column) FROM table_name;

MIN
SELECT MIN(column) FROM table_name;

GROUP BY
SELECT col,COUNT(*) FROM table_name GROUP BY col;

HAVING
SELECT col,AVG(col) FROM table_name GROUP BY col HAVING AVG(col)>80;

AND
... WHERE c1 AND c2;
OR
... WHERE c1 OR c2;

NOT
... WHERE NOT condition;

NOT EQUAL
<> or !=

Complete SQL Commands and Syntax for CBSE Class 12

DDL
 CREATE DATABASE
 USE DATABASE
 CREATE TABLE
 ALTER TABLE
 RENAME TABLE
 TRUNCATE TABLE
 DROP TABLE
 DESC

DML
 INSERT
 UPDATE
 DELETE

DQL
 SELECT
 DISTINCT
 WHERE
 ORDER BY
 GROUP BY
 HAVING

Constraints
 PRIMARY KEY
 FOREIGN KEY
 UNIQUE
 NOT NULL
 DEFAULT
 CHECK

Aggregate Functions
 COUNT()
 SUM()
 AVG()
 MAX()
 MIN()

String Functions
 UPPER()
 LOWER()
 LENGTH()
 MID()
 LEFT()
 RIGHT()
 CONCAT()
 LTRIM()
 RTRIM()
 REPLACE()

Numeric Functions
 ROUND()
 MOD()
 POWER()
 SQRT()
 ABS()
 CEIL()
 FLOOR()

Date Functions
 CURDATE()
 NOW()
 YEAR()
 MONTH()
 DAY()
 DATEDIFF()

Operators
 =, >, <, >=, <=, <>, !=
 AND
 OR
 NOT
 BETWEEN
 IN
 LIKE
 IS NULL
 IS NOT NULL

Useful Commands
 SHOW DATABASES;
 SHOW TABLES;
 DESC table_name;
 SELECT VERSION();
 SELECT DATABASE();

Common Syntax
 SELECT * FROM table_name;
 INSERT INTO table_name VALUES(...);
 UPDATE table_name SET column=value WHERE condition;
 DELETE FROM table_name WHERE condition;
 ALTER TABLE table_name ADD column datatype;
 CREATE TABLE table_name(column datatype);

You might also like