https://github.com/t-sibiraj/sql Light Mode Dark Mode Download More

TABLE OF CONTENTS:

TABLE OF CONTENTS: New topics will be added from time to time.DATABASE CONCEPTS:INTORDUCTION:DATABASERELATION aka Table:DOMAIN:TUPLE aka ROW:ATTRIBUTE AKA Column:Degree:Cardinality:KEY:Primary Key: Candidate Key: Alternate Key:Foreign Key:Advantages of SQL:SOME MYSQL SQL ELEMENTS:(i) Literals(have fixed value):(ii) Data Types:(I) Numeric :(I) Number:(II) Decimal/Float:(ii) CHARACTER OR STRING:(III) DATE AND TIME:TYPES OF SQL STATEMENTS (i)Data Definition Language (DDL) statement:(ii) Data Manipulation Language (DML) statement:SQLTABLE CREATION COMMANDS:SELECTSHOW AND DESCRIBE:ALIASING:TABLE ALIASES( PREREQUSITE : JOINS)COMMENTSWHERERELATIONAL OPERATORSBETWEENLIKE IN LOGICAL OPERATORORDER BYOPERATOR PRECEDENCE:AGGREGATE FUNCTIONS:MY SQL FUNCTIONSSTRING FUNTIONS: NUMERIC FUNTIONSDATE AND TIME FUNTIONSNull HandlingMISSED NUANCESTABLE CREATION COMMANDS (CONTINUED)DROPCONSTRAINTTABLE CONSTRAINTSNAMED CONSTRAINTSTABLE CREATION FROM EXISITNG TABLEUPDATEDELETE VS TRUNCATE (ROW OPERATION)ROLLBACK ALTER ADDCHANGEMODIFYADDDROPGROUP BY(COMING SOON)(IMPORTANT)JOINSCARTESIAN PRODUCTTABLE ALIASESEQUI - JOINNATURAL JOINEQUI JOIN VS NATURAL JOINPIPMYSQL CONNECTORCONNECTING TO MySQL DATABASECREATING A CURSOR INSTANCERECORDS TABLE:EXCECUTING QUERIESACCESSING STORED RESULTSET(OUTPUT) FROM THE CURSOR_OBJECTrowcount()connection_name.close()PYMYSQLPARAMETERISED QUERIESSTRING FORMATTINGcursor.commit()INSERTING RECORDS USING MYSQL.CONNECTOR()UPDATING RECORDS USING MYSQL.CONNECTOR() DELETING RECORDS USING MYSQL.CONNECTOR() SIMILARITY BETWEEN mysql.connector() and pythonTABLES USEDDATABASE PORTION FOR TERM - II(2021-2)

New topics will be added from time to time.

 

 

DATABASE CONCEPTS:

# SKIP TO SQL IF YOU ALREADY KNOW DATABASE CONCEPTS #

CLICK ME TO SKIP

EXTENDED READING FOR DATABASE CONCEPTS:

https://cbseacademic.nic.in/web_material/doc/cs/2_Computer_Science_Python_ClassXII.pdf

INTORDUCTION:

Let us consider school1 has a database. In which classes class 11 and class 12 are tables. In each class(tables) there are two columns(boys and girls). Each column has two rows(B has B1 , B2 as well as G has G1, G2)

SOURCE: t-sibiraj.github.io/learn

SOURCE: t-sibiraj.github.io/learn

DATABASE

 

RELATION aka Table:

 

DOMAIN:

A domain is a set of acceptable values of a particular column, which is based on various properties and data types.

Ad NoNameGenderMarital StatusSUBJECT
101AMALEUNMARRIEDMATH
105BFEMALEMARRIEDPHYSICS
203CMALEDIVORCEDCHEMSITRY
205DFEMALEWIDOWCOMPUTER SCIENCE

For example:

(i) The domain of gender column has a set of two possible values i.e, Male or Female.

(ii) The domain of marital status has a set of four possible values i.e, Married, Unmarried, Widows and Divorced

** (iii) The domain of subject has a set of five possible values i.e., Math's,physics,chemistry,computer science and English

 

TUPLE aka ROW:

ATTRIBUTE AKA Column:

Degree:

Cardinality:

KEY:

Key is of four types:

(i) Primary Key

(ii) Candidate Key

(iii) Foreign Key

(iv) Alternate Key

Primary Key:

 

Candidate Key:

Alternate Key:

Foreign Key:

A foreign key is a field (or collection of fields) in one table that uniquely identifies a row of another table. In other words, a foreign key is a column or a combination of columns that is used to establish a link between two tables.

 

SOURCE: t-sibiraj.github.io/learn

Resources:

 

Advantages of SQL:

 

SOME MYSQL SQL ELEMENTS:

(i) Literals(have fixed value):

 

(ii) Data Types:

(I) Numeric :

(I) Number:

 

(II) Decimal/Float:

 

(III) INT/INTERGER

(IV) FLOAT

(ii) CHARACTER OR STRING:

(III) DATE AND TIME:

 

TYPES OF SQL STATEMENTS

(i)Data Definition Language (DDL) statement:

DDL statements are used to create structure of a table, modify the existing structure of the table and remove the existing table. Some of the DDL statements are CREATE TABLE, ALTER TABLE and DROP TABLE.

Grant and revoke privileges and roles and maintenance commands

(ii) Data Manipulation Language (DML) statement:

Data Manipulation Language (DML) statements are used to access and manipulate data in existing tables. The manipulation includes inserting data into tables, deleting data from the tables, retrieving data and modifying the existing data. The common DML statements are SELECT, UPDATE, DELETE and INSERT.

(iii) Transaction Control Language (TCL) Commands:

COMMIT, ROLLBACK, SAVEPOINT, SET TRANSACTION

(iv) Session Control Commands

(v) System Control Commands

 


SQL

(Structured Query Language is a standard language used for accessing databases)

(ALL THE SQL COMMANDS WHICH ARE LISTED BELOW ARE COMPITABLE WITH MySQL

MySQL :https://dev.mysql.com/doc/

SQL Server:https://docs.microsoft.com/en-us/sql/sql-server/?view=sql-server-ver15)

 

  • SQL IS CASE INSENSITIVE


Consider

Name of the table --> records

snostudent_nameemailyearcolumn_name
1ramram@gmail.com200410
2samsam@yahoo.com200320
3harihari@outlook.com200230

TABLE CREATION COMMANDS:

 

 

SELECT

 

SHOW AND DESCRIBE:

ALIASING:

TABLE ALIASES( PREREQUSITE : JOINS)

COMMENTS

 

WHERE

RELATIONAL OPERATORS

BETWEEN

LIKE

IN

LOGICAL OPERATOR

 

ORDER BY

OPERATOR PRECEDENCE:

AGGREGATE FUNCTIONS:

 

 

MY SQL FUNCTIONS

STRING FUNTIONS:

NUMERIC FUNTIONS

DATE AND TIME FUNTIONS

Null Handling

MISSED NUANCES

TABLE CREATION COMMANDS (CONTINUED)

DROP

CONSTRAINT

TABLE CONSTRAINTS

NAMED CONSTRAINTS

TABLE CREATION FROM EXISITNG TABLE

UPDATE

DELETE VS TRUNCATE (ROW OPERATION)

image-20220113005614894

SOURCE: t-sibiraj.github.io/sql

ROLLBACK

ALTER

ADD

CHANGE

MODIFY

ADD

DROP

GROUP BY(COMING SOON)(IMPORTANT)

JOINS

CARTESIAN PRODUCT

image-20220113030716529

SOURCE: t-sibiraj.github.io/sql

image-20220113031336907

SOURCE: t-sibiraj.github.io/sql

TABLE ALIASES

 

EQUI - JOIN

source: t-sibiraj.github.io/learn

source: t-sibiraj.github.io/learn

source: t-sibiraj.github.io/learn

NATURAL JOIN

source: t-sibiraj.github.io/sql

source: t-sibiraj.github.io/learn

source: t-sibiraj.github.io/learn

EQUI JOIN VS NATURAL JOIN

source: t-sibiraj.github.io/learn

PIP

MYSQL CONNECTOR

CONNECTING TO MySQL DATABASE

CREATING A CURSOR INSTANCE

RECORDS TABLE:

 

EXCECUTING QUERIES

ACCESSING STORED RESULTSET(OUTPUT) FROM THE CURSOR_OBJECT

rowcount()

connection_name.close()

 

PYMYSQL

PARAMETERISED QUERIES

STRING FORMATTING

cursor.commit()

 

INSERTING RECORDS USING MYSQL.CONNECTOR()

UPDATING RECORDS USING MYSQL.CONNECTOR()

DELETING RECORDS USING MYSQL.CONNECTOR()

SIMILARITY BETWEEN mysql.connector() and python

TABLES USED

 

DATABASE PORTION FOR TERM - II(2021-2)


Creative Commons License

This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.

https://creativecommons.org/licenses/by-sa/4.0/legalcode


Copyright © 2022 T.Sibiraj. Some rights reserved.