0% found this document useful (0 votes)
21 views125 pages

ISM - Hunar Popli

Uploaded by

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

ISM - Hunar Popli

Uploaded by

r7vnjjwhvq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 125

1.

Steps to install MySql

• Step 1: Download MySQL Installer


• Open your web browser and navigate to the MySQL website at
https://dev.mysql.com/downloads/installer/.
• Scroll down to the “MySQL Installer” section, make sure “Microsoft Windows“ is
selected under Select Operating System and click on the “Download” button for
the MySQL Installer MSI (both the 2.4M and 331.3M version will work)
On the next page, you’ll be prompted to log in or create a MySQL
account. You can choose “No thanks, just start my download.”
Step 2: Install and Configure MySQL

• Locate the installer file you just downloaded (e.g., mysql-installer-web-


community-x.x.xx.x.msi) and double-click it to run the installer.

In the installer window, choose “Full” under “Setup Type.” This option will install
MySQL Server, MySQL Workbench and other components, such as documentation
and examples. Then click “Next.”
In the next window, just click “Execute.”
After all products have been downloaded sucessfully, as indicated
by the green checkmark, click “Next.
In the next window, just click “Execute.”
After all products have been installed successfully, click “Next” to start the configuration.
Under “Type and Networking” choose “Development Computer” as
Config Type and leave everything else as is. Then click “Next.”
Next, you will be asked to choose an authentication method. For increased compatibility, choose “Use Legacy Authentication Method” and click “Next.” Choosing “Use Strong Password Encryption” will also work.
In the “Account and Roles” window, choose a new password for your
root account. Be sure to choose a strong password and enter the password
under MySQL Root Password and Repeat Password then click “Next.”
In the next window, leave everything as is and click “Next.”
Next, grant full access to let the Installer update server file permissions and click “Next.” Click “Execute” to apply the configuration changes.
Once the configuration is done (green checkmarks), click “Finish.”
Click “Next” to start the configuration .
Under “Connect To Server” enter the password you chose earlier under Password and click “Check.”
If the password was correct, a green checkmark will appear and the status of the connection will change to “Connection succeeded.”
Click “Next”
Click “Execute” to apply the configurations.
Once the configuration is completed (green checkmarks), click “Finish.”
That’s it! The installation is complete. You can now choose whether MySQL Workbench and Shell should be
launched — we only need MySQL Workbench right now .

• Click “Finish” and MySQL Workbench will launch


Step 3: Using MySQL Workbench

• At the end of the installation process, MySQL Workbench should launch


automtically. If it doesn’t, start the programm manually. You are greeted by the
graphical user interface (GUI) tool for MySQL, the MySQL Workbench.
• In the bottom half of the window under “MySQL Connections” you should see
one tile for your local instance connection, Local instance MySQL80.
• Go ahead and double-click it.
In the new window, enter the password you chose earlier and click “OK.”
And we’re in. You are now connected to your MySQL Server and can
start using the MySQL Workbench.
The Navigator is typically located on the left-hand side of the MySQL
Workbench GUI. It serves as a central hub for database management
and navigation. It houses some administrative features and a handy
tree-like structure of all your databases under the tab “Schemas.”
The “Query” tab, located in the middle of the workspace area, is where
you can write and execute SQL queries. This is where you interact
with your MySQL databases using SQL commands.
The “Output” tab, usually positioned at the bottom of the MySQL
Workbench interface, displays various types of information and
feedback. This includes feedback on the (successful) execution of your
SQL queries, any error messages, and status updates regarding your
MySQL server.
Step 4: Testing the Connection

• To test your connection, use the following steps:


• In MySQL Workbench, open a new query tab by clicking the “+ SQL” icon in the
top left corner or selecting “File” > “New Query Tab.”
You can use a basic SQL query to test the connection. For example, you
can run a query to display the current date and time:

SELECT NOW();
This query will retrieve the current date and time from the MySQL server. If you
receive a result with the current date and time, it confirms that your connection to
the MySQL server is working.

Enter SELECT NOW() into the new query tab.


Click the “Execute” button (lightning bolt symbol) or press Ctrl+Enter to execute
the query.
If the query executes successfully and you see the current date and time
in the result pane, it means that your connection to the MySQL server is
functioning correctly. If you get an error or don’t see any results, it could
indicate a connection issue. In that case, double-check your connection
settings, including the hostname, port, username, and password, and
ensure your MySQL server is running.
2. Types of SQL commands
Data Definition Language(DDL)
• DDL (Data Definition Language) commands define and modify the structure
of database objects like tables, indexes, and views. These commands deal with
creating, altering, and removing the schema rather than the data itself.
• DDL commands are auto-commit, meaning the changes take effect
immediately and cannot be rolled back.

• DDL Commands:
1. CREATE: Defines and creates new objects like tables, indexes, or views. It
establishes the structure of a database by specifying fields, types, and
constraints.
2. ALTER: Modifies the structure of existing objects, such as adding or deleting
columns, changing data types, or renaming objects.
3. DROP: Permanently removes objects from the database, including all their data
and structure.
4. TRUNCATE: Deletes all records in a table but keeps its structure intact for
future use.
5. RENAME: Changes the name of an existing object, like a table, without
affecting its structure or data.
• Each of these commands directly alters the database schema and triggers auto-
commit, making the changes permanent

Data Manipulation Language (DML)


DML (Data Manipulation Language) commands are used to interact with and
manipulate data within the database. These commands allow you to retrieve, insert,
update, and delete records from database tables.
• DML Commands:
1. SELECT: Retrieves data from one or more tables based on specified criteria
without modifying the data.
2. INSERT: Adds new rows of data into a table.
3. UPDATE: Modifies existing records in a table based on specified conditions.
4. DELETE: Removes specific rows from a table based on conditions.

• DML commands allow direct manipulation of the data while ensuring data
integrity through transactions.
Transaction Control Language(TCL)
• TCL (Transaction Control Language) commands are used to manage and
control the transactions within a database. They ensure that all DML changes are
either saved or undone, maintaining data integrity during database operations.
• TCL commands depend on the transactional context and apply once the
transaction is complete.

• TCL Commands:
• COMMIT: Saves all changes made during the current transaction permanently to
the database.
• ROLLBACK: Reverts all changes made during the current transaction, returning
the database to its previous state.
• SAVEPOINT: Sets a point within a transaction to which you can later rollback
without affecting the entire transaction.
• These commands allow for precise control over transactions, ensuring consistent
and reliable database operations.

Data Control Language(DCL)


• DCL (Data Control Language) commands are used to control access and
permissions to the database and its objects. They manage user rights and
privileges, ensuring that only authorized users can perform specific actions on the
database.
• DCL commands take effect immediately, altering access rights without needing
additional transactions.
Data Control Language(DCL)

• DCL Commands:
• GRANT: Assigns specific privileges or permissions to users or roles, allowing
them to perform certain actions like SELECT, INSERT, or DELETE on database
objects.
• REVOKE: Removes previously granted privileges from users or roles, preventing
them from performing specific actions on database objects.

• These commands are essential for managing database security and ensuring that
users have appropriate access levels based on their roles.
3. Keys in SQL
Keys play an important role in the relational database. It is used to uniquely identify
any record or row of data from the table. It is also used to establish and identify
relationships between tables.
• Primary Key: Uniquely identifies a record; must be unique and cannot be NULL.
• Foreign Key: Links to a primary key in another table, ensuring referential
integrity.
• Unique Key: Ensures uniqueness for a column while allowing NULLs (only one
NULL).
• Composite Key: A combination of columns that uniquely identify a record.
• Candidate Key: Potential primary keys that can uniquely identify records; one is
selected as primary.
• Alternate Key: A candidate key that is not chosen as the primary key.
• Super Key: Any combination of attributes that can uniquely identify a record;
broader than a primary key.

• These keys are essential in database design, enabling efficient data retrieval,
4. Integrity Constraints

• Primary Key Constraint: Guarantees uniqueness and non-nullability for primary


identifiers.
• Foreign Key Constraint: Maintains referential integrity between tables.
• Unique Constraint: Ensures all values in a column are unique.
• Check Constraint: Validates values against specified conditions.
• Not Null Constraint: Prevents NULL values in specified columns.
• Default Constraint: Assigns default values to columns when no explicit value is
provided.

• These integrity constraints are fundamental to ensuring the accuracy, consistency,


and integrity of data within a database.
SQL PRIMARY KEY Constraint

The PRIMARY KEY constraint uniquely identifies each record in a table.


Primary keys must contain UNIQUE values, and cannot contain NULL values.
A table can have only ONE primary key; and in the table, this primary key can
consist of single or multiple columns (fields).

SQL PRIMARY KEY on CREATE TABLE SQL PRIMARY KEY on ALTER TABLE

The following SQL creates a PRIMARY To create a PRIMARY KEY constraint on


KEY on the "ID" column when the the "ID" column when the table is
"Persons" table is created: already created, use the following
SQL:
CREATE TABLE Persons (
ID int NOT NULL, ALTER TABLE Persons
LastName ADD PRIMARY KEY (ID);
varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
PRIMARY KEY (ID)
);
SQL FOREIGN KEY Constraint

The FOREIGN KEY constraint is used to prevent actions that would destroy links
between tables. A FOREIGN KEY is a field (or collection of fields) in one table, that
refers to the Primary Key in another table. The table with the foreign key is called the
child table, and the table with the primary key is called the referenced or parent
table.
SQL FOREIGN KEY on CREATE SQL FOREIGN KEY on ALTER TABLE
TABLE
To create a FOREIGN KEY constraint on
The following SQL creates a FOREIGN the "PersonID" column when the
KEY on the "PersonID" column when "Orders" table is already created, use
the "Orders" table is created: the following SQL:

CREATE TABLE Orders ( ALTER TABLE Orders


OrderID int NOT NULL, ADD FOREIGN KEY (PersonID) REFER
OrderNumber int NOT NULL, ENCES Persons(PersonID);
PersonID int,
PRIMARY KEY (OrderID),
FOREIGN KEY (PersonID) REFER
ENCES Persons(PersonID)
);
SQL UNIQUE Constraint

The UNIQUE constraint ensures that all values in a column are different. A PRIMARY
KEY constraint automatically has a UNIQUE constraint. However, you can have
many UNIQUE constraints per table, but only one PRIMARY KEY constraint per table.

SQL UNIQUE Constraint on CREATE SQL UNIQUE Constraint on ALTER


TABLE TABLE

The following SQL creates To create a UNIQUE constraint on the


a UNIQUE constraint on the "ID" column "ID" column when the table is already
when the "Persons" table is created: created, use the following SQL:

CREATE TABLE Persons ( ALTER TABLE Persons


ID int NOT NULL, ADD UNIQUE (ID);
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
UNIQUE (ID)
);
SQL CHECK Constraint

The CHECK constraint is used to limit the value range that can be placed in a column.
If you define a CHECK constraint on a column it will allow only certain values for this
column. If you define a CHECK constraint on a table it can limit the values in certain
columns based on values in other columns in the row.

SQL CHECK on CREATE TABLE SQL CHECK on ALTER TABLE

The following SQL creates a CHECK constraint To create a CHECK constraint on the
on the "Age" column when the "Persons" table "Age" column when the table is
is created. The CHECK constraint ensures that already created, use the following
the age of a person must be 18, or older: SQL:

CREATE TABLE Persons ( ALTER TABLE Persons


ID int NOT NULL, ADD CHECK (Age>=18);
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
CHECK (Age>=18)
);
SQL NOT NULL Constraint

By default, a column can hold NULL values.


The NOT NULL constraint enforces a column to NOT accept NULL values.
This enforces a field to always contain a value, which means that you cannot insert a
new record, or update a record without adding a value to this field.

SQL NOT NULL on CREATE TABLE SQL NOT NULL on ALTER TABLE
The following SQL ensures that the To create a NOT NULL constraint on
"ID", "LastName", and "FirstName" the "Age" column when the "Persons"
columns will NOT accept NULL values table is already created, use the
when the "Persons" table is created: following SQL:
CREATE TABLE Persons ( ALTER TABLE Persons
ID int NOT NULL, MODIFY COLUMN Age int NOT NULL;
LastName
varchar(255) NOT NULL,
FirstName
varchar(255) NOT NULL,
Age int
);
SQL DEFAULT Constraint

The DEFAULT constraint is used to set a default value for a column.


The default value will be added to all new records, if no other value is specified.

SQL DEFAULT on CREATE TABLE SQL DEFAULT on ALTER TABLE

The following SQL sets a DEFAULT value To create a DEFAULT constraint on the
for the "City" column when the "Persons" "City" column when the table is
table is created: already created, use the following
SQL:
CREATE TABLE Persons (
ID int NOT NULL, ALTER TABLE Persons
LastName varchar(255) NOT NULL, ALTER City SET DEFAULT 'Sandnes'
FirstName varchar(255), ;
Age int,
City
varchar(255) DEFAULT 'Sandnes'
);
5. CREATE DATABASE
6. OPEN DATABASE
7. CREATE TABLES

i) Persons (P_id, Lname, Fname, Address, Salary, City, D_id, Pj_id)


SETTING DEFAULT VALUE OF SALARY
ii) Dept (D_id, D_name, D_floor)
iii) Project (Pj_id, Pj_name, Pj_duration, Pj_dept, Pj_d_id)
8. VIEW TABLE DESCRIPTION USING
DESC PERSONS
9. VIEW TABLE DESCRIPTION USING
DESCRIBE DEPT
VIEW TABLE DESCRIPTION USING DESCRIBE PROJECT
DISPLAYING EFFECT OF DEFAULT CONSTRAINT
10. INSERT RECORDS
i) Inserting records (19 records) in Persons table
Inserting Record using default salary
Displaying all records of Persons Table
ii) Inserting records in dept table
Displaying all records of dept table
iii) Inserting records in Project Table
Displaying all records of project table
11. PRIMARY KEY
i) Persons- P_id
ii) Dept- D_id
iii) Project- Pj_id
12. FOREIGN KEY
i) D_id in Persons references D_id in Department
ii) Pj_id in Persons references Pj_id in Project
13. ALTER TABLE & CHECK CONSTRAINT
Add gender in Persons after Fname. Gender should be Male, Female or Others.
Delete column Pj_duration from Project table.
14. RENAME TABLE PROJECTS TO
APRIL_PROJECTS
15. SHOW TABLE STRUCTURE PERSONS
16. UPDATE TABLE
Add details for gender column
Update P_id to 103 for person whose last name is “Goyal"
17. DELETE STATEMENT
Delete the record of the person whose P_id is 1002.
18. VIEW ALL RECORDS
19. VIEW SELECTIVE RECORDS USING
WHERE CLAUSE
Display the details of persons whose department id is 1111.
20. VIEW SELECTIVE FIELDS
Display P_id, Fname & Salary of all persons
22. AND OPERATOR
Display the details of persons whose reside is Delhi & whose
department id is 1111.
23. OR OPERATOR
Display the details of persons whose reside is Delhi or whose
department id is 1111.
24. ORDER BY CLAUSE
Display the details of all the persons in ascending order of their names
Display the details of all the persons in descending order of their
Department Ids.
25. LIKE OPERATOR
i) Display the details of all the persons whose city name contains
the pattern "elh".
ii) Display the details of all the persons whose second alphabet of the
name is 'a'.
iii) Display the details of all the persons whose lastname starts with 'B' or 'S'.
iv) Display the details of all the persons whose lastname does not start
with 'B','S' or 'P'.
26. IN OPERATOR
Display the details of all the persons who reside in Delhi, Mumbai or Kolkata.
27. BETWEEN OPERATOR
Display the details of all the persons whose department id is between 2
to 6.
28. VIEW LIST OF DATABASES
29. VIEW LIST OF TABLES IN A DATABASE
Delete a record
30. DROP COMMAND
Delete a database
Delete table April_Projects
31. SUM FUNCTION
Calculate the TotalSalaries of all the persons whose department id is
1111.
32. GROUP BY STATEMENT
Display D_id and corresponding TotalSalaries of all the departments
33. HAVING CLAUSE
Display D_id and corresponding total salaries of all the departments
having total salaries greater than 70,000.
34. CREATE TABLE ORDERS
(O_Id,OrderDate,OrderPrice,Customer)
35. AVG FUNCTION
Display the names of customers whose Order Price is greater than the
average Order Price from Orders table.
36. COUNT FUNCTION

Display the total number of records in orders table


37. COUNT DISTINCT
Count Distinct Customers from Orders Table
38. MAX FUNCTION
Display the maximum Order Price from Orders table.
39. MIN FUNCTION
Display the minimum Order Price from Orders table.
40. UCASE FUNCTION
Display the customer names from Orders table in capital letters or
uppercase.
41. LCASE FUNCTION
Display the customer names from Orders table in small letters or
lowercase.
42. MID FUNCTION
Display the first 3 alphabets of city from Persons table.
43. LENGTH FUNCTION
Display all the addresses along with their corresponding length from Persons
table.
44. CROSS JOIN
Tables- Persons & Department
45. INNER JOIN
Tables- Persons & Department
46. LEFT OUTER JOIN
Tables- Persons & Department
47. RIGHT OUTER JOIN
Tables- Persons & Department
48. Create table Project1 and Project2 having
attributes E_Id, E_Name, Dept_Id)
49. UNION ALL
Tables- Project1 and Project-2
50. UNION
Tables- Project1 and Project-2
51. COMMIT

You might also like