[go: up one dir, main page]

0% found this document useful (0 votes)
11 views11 pages

Database Management Notes_2

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)
11 views11 pages

Database Management Notes_2

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
You are on page 1/ 11

Computer Science (2024-25)

CLASS XII Code No. 083

DATABASE MANAGEMENT SYSTEM

 JOINS

CARTESIAN PRODUCT

A Cartesian product is the result of joining every row in one table with every row in another
table. This occurs when there is no WHERE clause to restrict rows.

Example:
SELECT eno,ename,title,salary,pno,pname,budget FROM emp,proj;

EQUI-JOIN and NATURAL JOIN


Equi Join is a join having a condition where we use an equal operator. While performing a
natural join, we do not use an equal operator. We use Equi Join if we need both tables in the
output without missing any column. We use Natural Join if we need only the unique columns
without repetition.

Example:

NATURAL-JOIN:

SELECT * FROM Student NATURAL JOIN Student_Marks;


Where Student is table 1 and Student_Marks is table 2

EQUI-JOIN:

SELECT * FROM Student INNER JOIN Student_Marks ON Student.S_ID=Student_Marks.S_Name;

Where Student is table 1 and Student_Marks is table 2.


S_ID is an attribute of Student.
S_Name is an attribute of Student_Marks.

 INTERFACE OF PYTHON:
Install MySQL Driver
Python needs a MySQL driver to access the MySQL database.
In this tutorial we will use the driver "MySQL Connector".
We recommend that you use PIP to install "MySQL Connector".
PIP is most likely already installed in your Python environment.
Navigate your command line to the location of PIP, and type the following:

Download and install "MySQL Connector":

C:\Users\Your Name\AppData\Local\Programs\Python\Python36-32\Scripts>python -m pip install


mysql-connector-python

Create Connection
Start by creating a connection to the database.
Use the username and password from your MySQL database:

Creating a Database
To create a database in MySQL, use the "CREATE DATABASE" statement:
Creating a Table
To create a table in MySQL, use the "CREATE TABLE" statement.
Make sure you define the name of the database when you create the connection

To show tables
Primary Key
When creating a table, you should also create a column with a unique key for each record.
This can be done by defining a PRIMARY KEY.

If the table already exists, use the ALTER TABLE keyword:


To insert values into the table:

Notice the statement: mydb.commit(). It is required to make the changes, otherwise no


changes are made to the table.
Insert Multiple Rows:
To insert multiple rows into a table, use the executemany() method.
The second parameter of the executemany() method is a list of tuples, containing the data you
want to insert:

Select From a Table


To select from a table in MySQL, use the "SELECT" statement:
We use the fetchall() method, which fetches all rows from the last executed statement.
Selecting Columns
To select only some of the columns in a table, use the "SELECT" statement followed by the
column name(s):
Select With a Filter
When selecting records from a table, you can filter the selection by using the "WHERE"
statement:

To sort the data in the table:


Use the ORDER BY statement to sort the result in ascending or descending order.
The ORDER BY keyword sorts the result ascending by default. To sort the result in descending
order, use the DESC keyword.
Delete Record
You can delete records from an existing table by using the "DELETE FROM" statement:
Notice the statement: mydb.commit(). It is required to make the changes, otherwise no
changes are made to the table.
The WHERE clause specifies which record(s) that should be deleted. If you omit the WHERE
clause, all records will be deleted.

You might also like