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

DATABASE CONCEPTS:

# SKIP TO SQL IF YOU ALREADY KNOW DATABASE CONCEPTS #

EXTENDED READING FOR DATABASE CONCEPTS:

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

 

DATABASE

 

RELATION:

 

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:

 

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.

 

Degree:

 

Cardinality:

‪ SOURCE: cbseacademic.com

 

https://www.guru99.com/images/1/100518_0517_DBMSKeysPri1.png

SOURCE:www.guru99.com

 

SOURCE: powerbidocs.com

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) DAT 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

s.nostudent_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

PIP

image-20220113034025814

SOURCE: pypi.org

PyPI website homepage

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

 

Hits