0% found this document useful (0 votes)
34 views6 pages

PPUD

This document provides syntax examples for common SQL statements like UPDATE, SELECT, INSERT, DELETE, ALTER TABLE, CREATE TABLE with PRIMARY KEY and FOREIGN KEY. It also covers SQL functions like COUNT, AVG, SUM, MIN and MAX. Stored routines are defined as reusable sets of SQL statements that can be called instead of reissuing individual statements.

Uploaded by

Talonted Gamer
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)
34 views6 pages

PPUD

This document provides syntax examples for common SQL statements like UPDATE, SELECT, INSERT, DELETE, ALTER TABLE, CREATE TABLE with PRIMARY KEY and FOREIGN KEY. It also covers SQL functions like COUNT, AVG, SUM, MIN and MAX. Stored routines are defined as reusable sets of SQL statements that can be called instead of reissuing individual statements.

Uploaded by

Talonted Gamer
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/ 6

UPDATE Syntax

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

SELECT Syntax
SELECT column1, column2, ...
FROM table_name;

WHERE Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition;

INSERT INTO Syntax


It is possible to write the INSERT INTO statement in two ways:
1. Specify both the column names and the values to be inserted:

INSERT INTO table_name (column1, column2, column3, ...)


VALUES (value1, value2, value3, ...);

DELETE Syntax
DELETE FROM table_name WHERE condition;
MySQL MIN() and MAX() Functions
The MIN() function returns the smallest value of the selected column.
The MAX() function returns the largest value of the selected column.

MIN() Syntax
SELECT MIN(column_name)
FROM table_name
WHERE condition;

MAX() Syntax
SELECT MAX(column_name)
FROM table_name
WHERE condition;

MySQL COUNT(), AVG() and SUM() Functions


The COUNT() function returns the number of rows that matches a specified criterion.

COUNT() Syntax
SELECT COUNT(column_name)
FROM table_name
WHERE condition;

The AVG() function returns the average value of a numeric column.

AVG() Syntax
SELECT AVG(column_name)
FROM table_name
WHERE condition;

The SUM() function returns the total sum of a numeric column.

SUM() Syntax
SELECT SUM(column_name)
FROM table_name
WHERE condition;
ALTER TABLE - ADD Column
To add a column in a table, use the following syntax:

ALTER TABLE table_name


ADD column_name datatype;

PRIMARY KEY on CREATE TABLE


The following SQL creates a PRIMARY KEY on the "ID" column when the "Persons" table is
created:

CREATE TABLE Persons (


ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
PRIMARY KEY (ID)
);

FOREIGN KEY on CREATE TABLE


The following SQL creates a FOREIGN KEY on the "PersonID" column when the "Orders" table is
created:

CREATE TABLE Orders (


OrderID int NOT NULL,
OrderNumber int NOT NULL,
PersonID int,
PRIMARY KEY (OrderID),
FOREIGN KEY (PersonID) REFERENCES Persons(PersonID)
);
STORED ROUTINES
A stored routine is a set of SQL statements that can be stored in the server. Once this
has been done, clients don't need to keep reissuing the individual statements but can
refer to the stored routine instead.

You might also like