2-MySQL All Commands
2-MySQL All Commands
Table Commands
Keys in MySQL
Constraints in MySQL
Views
Manipulation Commands
Joins
Index
Triggers
Transaction Commands
5-SHOW SCHEMAS;
6-SHOW DATABASES;
9-USE PatientsDatabase;
PatientID int,
PatientName varchar(255),
Sex varchar(255),
Age int,
Address varchar(255),
PostalCode int,
State varchar(255),
Country varchar(255),
RegDate date
);
FROM Patients;
13-USE PatientsDatabase;
15-DESCRIBE Patients;
PatientID,PatientName,Sex,Age,Address,PostalCode,State,Country,RegDate date
) VALUES ('06', 'Suhana','F', ‘12’, 'House No 34C Jubilee Hills', '500046', ‘Telangana’, 'India',
‘02/09/2021’);
–OR
20-INSERT INTO Patients VALUES ('06', 'Suhana','F', ‘12’, 'House No 34C Jubilee Hills', '500046',
‘Telangana’, 'India', ‘02/09/2021’);
21-UPDATE Patients
WHERE PatientID = 1;
WHERE PatientName='Anay';
–OR
–OR
–OR
–OR
--OR
--OR
—OR
–OR
PatientName varchar(255),
Sex varchar(255),
Age int,
Address varchar(255),
PostalCode int,
State varchar(255),
Country varchar(255),
RegDate date
);
DoctorName varchar(255),
);
PatientName varchar(255),
Sex varchar(255),
Age int,
Address varchar(255),
PostalCode int,
State varchar(255),
Country varchar(255),
RegDate date
);
PatientName varchar(255),
Age int,
Address varchar(255),
PostalCode int,
State varchar(255),
Country varchar(255),
);
PatientID int,
PatientName varchar(255),
Sex varchar(255,
Address varchar(255),
PostalCode int,
State varchar(255),
Country varchar(255),
RegDate date
);
PatientID int,
PatientName varchar(255),
Sex varchar(255),
Address varchar(255),
PostalCode int,
State varchar(255),
Country varchar(255),
);
FROM Patients
);
FROM Patients
);
MySQL Clauses
-ORDER BY Age;
FROM Patients
GROUP BY State
ORDER BY COUNT(PatientID);
FROM Patients
GROUP BY State
-Use of Operators
58-SELECT PatientName
FROM Patients
59-SELECT PatientName
FROM Patients
WHERE PatientID = ALL (SELECT PatientID FROM Patients WHERE Age < 35);
60-SELECT PatientName
FROM Patients
WHERE PatientID = ANY (SELECT PatientID FROM Patients WHERE BETWEEN 20 AND 35);
61-SELECT PatientName
FROM Patients
–OR
62-SELECT PatientName
FROM Patients
-AGGREGATE FUNCTIONS
63-SELECT SUM(Age)
FROM Patients;
FROM Patients;
65-SELECT MIN(Age)
FROM Patients;
66-SELECT MAX(Age)
FROM Patients;
67-SELECT COUNT(Age)
FROM Patients;
FROM Patients
LIMIT 1;
FROM Patients
LIMIT 3;
FROM Patients
LIMIT 1;
-SET OPERATIONS
UNION
INTERSECT
MINUS
-Joins
FROM Diseases
ORDER BY Diseases.DiseaseID;
FROM Diseases
ORDER BY Diseases.DiseaseID;
FROM Diseases
FROM Diseases
-Triggers
Triggers are a set of SQL statements that are invoked automatically in response to an event. Every
trigger, associated with a table, is activated by DML commands such as INSERT, UPDATE, and
DELETE.
Row-Level Trigger: Activated for each row, affected by INSERT, UPDATE or DELETE
commands.
Statement-Level Trigger: Activated for each of the events which occurs, irrespective of any of the
DML commands.
Before Insert: Activated before the data is inserted into the table.
After Insert: Activated after the data is inserted into the table..
Before Delete: Activated before the removal of data from the table.
After Delete: Activated after the removal of data from the table.
Before Update: Activated before the data being updated in the table.
After Update: Activated after the data being updated in the table
Syntax:
BEGIN
--Declarations
--Trigger Code
END;
Transaction commands deal with all the transactions related to the database. The commands are:
COMMIT
ROLLBACK
SAVEPOINT
RELEASE SAVEPOINT
SET TRANSACTION
84. COMMIT
Used to save all the transactions of the database since the last COMMIT or ROLLBACK command.
Syntax:
COMMIT;
Example:
COMMIT;
85. ROLLBACK
Used to undo all the transactions since the last COMMIT or ROLLBACK.
Syntax:
ROLLBACK;
Example:
86. SAVEPOINT
Used to roll the transaction back to a certain point without actually rolling back the entire transaction.
Syntax:
SAVEPOINT SAVEPOINTNAME;
ROLLBACK TO SAVEPOINTNAME;
Example:
SAVEPOINT EX1;
SAVEPOINT EX2;
Syntax:
Example:
Syntax: