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

Database Note

The document provides a comprehensive guide on basic SQL commands for database management, including creating databases and tables, inserting data, and querying with various clauses. It covers essential operations such as updating, deleting, and joining tables, as well as using constraints and aggregate functions. Additionally, it explains advanced topics like transactions, subqueries, and the use of operators like IN, LIKE, and BETWEEN.

Uploaded by

dasiyarvanshi
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)
3 views5 pages

Database Note

The document provides a comprehensive guide on basic SQL commands for database management, including creating databases and tables, inserting data, and querying with various clauses. It covers essential operations such as updating, deleting, and joining tables, as well as using constraints and aggregate functions. Additionally, it explains advanced topics like transactions, subqueries, and the use of operators like IN, LIKE, and BETWEEN.

Uploaded by

dasiyarvanshi
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

Database Note

1. To create Databse
Create database database_name;
Use database_name;

2. To create Table
Create table table_name
(
column1 datatype, Constraints
column2 datatype Not null
); Unique

Default
3. Add data into Tables using Insert Quary Check
INSERT INTO table_name ( column1,column 3) values
Foreign key
(value1,value2,……),
Primary key
(value1,va;ue2,……);

4. Select Quary with Where Clause


SELECT column1,column2,… from table_name;
SELECT * from table_name ;
SELECT * from table_name WHERE condition; (eg. Age >20 )

5. Table Constraints
(
Id int NOT NULL UNIQUE,
Age tinyint CHECK(age >18),
Status boolean DEFAULT 1
)
6. Commands: And,Or &n Not Operator
SELECT * from table_name WHERE Condn1 AND Condn2 OR Condn3
SELECT * from table_name WHER NOT cond1 AND cond2 ORcond3
7. In Operator on database Table
SELECT *from table_name WHERE column_name IN (value1,value2,
…);
Eg. SELECT *from table_name WHERE age IN (19,23,12);

8. Like Operator and Wildcard

SELECT *from table_name WHERE name LIKE “a%”;

9. Between and Not Between Operator


Eg. SELECT * from student WHERE age BETWEEN 20 AND 25;
Eg. SELECT * from student WHERE age NOT BETWEEN 20 AND 25;

10. Order By and Distinct


SELECT *from student ORDER BY column_name ASC /DESC;
SELECT DISTINCT city from student;

11. Is Null and Is not Null Operator


SECLECT *from table_name WHERE column_name IS NULL / IS NOT
NULL;

12. Limit and Offset Complete Tutorial


SELECT * from student LIMIT 5;
SELECT * from student OFFSET 1;( mean skip1 and start from 2)
13. Aggregate Functions: Sum,Min,Max& Avg

SELECT count (id) from student WHERE fees>5000;


SELECT sum(fees) from student ;

14. Update Statement or data in


Don’t forget to go tho the table of
Table field and change the primary key
UPDATE table_name
SET fieldd1 = new_value1,
Field2 =new_value2 [WHERE Clause]

Eg. UPDATE student SET age =20 WHERE id =2;

15. Detele data from Table


DETELE from table_name [WHERE Clause]
Eg. DETELE from student WHERE id =5;

16. Primary key and Foreign key using command

17. Data Transaction (Commit & Rollback)


When you chose commit; there is no rollback;

18. Primary key and Foreign key


Foreign key is which reference to the primary key of other table,
Eg. Foreign key (city) references cities(id)
19. Inner Join Command
SELECT columns from table1
INNER JOIN table2 ON table1.column_name= table2.column_name;

20. Different between Left vs Right Join

21. Cross Join in Mysql

22. How to multiple Tables using Command?


23. SubQuery with Exists & Not Exists Explanation

24. Mysql Group by Having Clause

You might also like