0% found this document useful (0 votes)
1K views9 pages

On MYSQL COMMANDS

The document summarizes key SQL commands used in MySQL including creating and modifying tables, inserting and deleting data, joining tables, and using aggregate functions. It describes how to create tables with the CREATE TABLE command and specify columns and data types. It also explains how to insert and update data using INSERT and UPDATE commands, delete rows with DELETE, and alter tables structure with ALTER TABLE. Additional SQL topics covered include joins with SELECT, sorting results with ORDER BY, and grouping data and calculating aggregates with GROUP BY and functions like COUNT, SUM, AVG, MAX, and MIN.
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)
1K views9 pages

On MYSQL COMMANDS

The document summarizes key SQL commands used in MySQL including creating and modifying tables, inserting and deleting data, joining tables, and using aggregate functions. It describes how to create tables with the CREATE TABLE command and specify columns and data types. It also explains how to insert and update data using INSERT and UPDATE commands, delete rows with DELETE, and alter tables structure with ALTER TABLE. Additional SQL topics covered include joins with SELECT, sorting results with ORDER BY, and grouping data and calculating aggregates with GROUP BY and functions like COUNT, SUM, AVG, MAX, and MIN.
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/ 9

K.V.

JYOTIPURAM

SUB. : COMPUTER SCIENCE

The topic is: MYSQL SQL COMMANDS


Presented by: Anurag Kesar
Class: 12Th ‘A’
Roll no.: 03

Presented to: Ms. Parul Mam


ACCESSING DATABASE IN MYSQL
1. Creating table in MYSQL:

Tables are in MYSQL with the CREATE TABLE command.

When a table is created, its column, data types are named and sizes are supplied for each column. Each table must have at
least one column.

Syntax: Create table:

CREATE TABLE < table name >(<column more> <data type>)[(size)](<column name> <data types>)[(<size>)……..]

2. Inserting data into tables:

Rows are added to relations (tables) using INSERT command of SQL.

Syntax : INSERT <table name>[<column list>] VALUES (<value>, <value>,………);

Example; INSERT INTO <table name>[<column lists>] VALUES (<value>, <value>………);

NOTE: data values are in the same order as the column names in the table i.e. data can be added only to some columns in a
row by specifying the columns and their data.
DEFAULT VALUE :
• A preselected option adopted by a computer program when no alternative is specified by the user or programmer.

• The column that are not inserted in the INSERT command will have their default value, if it is defined for them, otherwise
NULL value.

• If any other column (that does not have a default value and is defined NOT NULL) is skipped, an error message is generated
and the row is not added.

MODIFYING DATA IN TABLES :

• Data is modified in tables using UPDATE command of SQL.

• The UPDATE command specifies the rows to be changed using the WHERE clause and the new data using the SET
KEYWORD.

• Example; UPDATE items SET ROLL= 250

DELETING DATA FROM TABLES:

• To delete data from tables, SQL delete commands are used.

• Delete command removes rows from a table i.e. this removes entire rows not individual field values.

• Syntax: DELETE FROM <table name> [WHERE <predicate>]

• If no condition is specified with WHERE, then all the rows of the tables will be deleted.
ALTERING TABLES:
• The ALTER table command is used to change definitions of existing tables.

1. Usually, it is used to add columns to a table.

• Syntax: ALTER TABLE <table name> ADD <column name> <data type> <size>;

2. Using Alter table command to modify data:

• ALTER TABLE <table name> MODIFY (column name new data type(new size)) [FIRST | AFTER column];

3. To change the name of one of the columns:

• ALTER TABLE CHANGE [CHANGE] old_col_name new_col_name column_definition;

DROPPING TABLES:
The drop table command of SQL is used to drop a table from the database.

SYNTAX : DROP TABLE [IF EXISTS] <table name>;

• The [IF EXISTS] clause of Drop table first checks whether the given table exists in the database or not.

• If it does, then it drops the mentioned table from the database.


SQL JOINS:

• A SQL Join is a query that fetches data from the two or more tables whose records are joined with one another
based on condition.

• Syntax: SELECT <field list> FROM <table 1>, <table 2> ,[<table 3>.....] WHERE < join condition for the tables>

ORDER BY CLAUSE:

• Order by clause sets the result generated by the SQL SELECT statement in ascending or descending order.

• Syntax: SELECT <comma separated select list> from <table> [WHERE <condition>] ORDER BY <field name>
[ASC | DESC], [<file name> [ASC | DESC],…..]

• Where ASC: ASCENDING ORDER

& DESC: DESCENDING ORDER.


AGGREGATE FUNCTIONS:
Also known as multiple row functions as these functions work upon groups of rows, rather than on
single rows.

OPTIONS FOR FUNCTIONS:

1. Distinct: this option causes a group function to consider only distinct values of the argument
expression.

2. ALL: this option causes a group function to consider all values including all duplicates.

3. AVG: computers average of given data.

Syntax: AVG( [ DISTINCT | ALL] n)


-Returns average value of n- parameters
-Argument type: Numeric
-Return value: Numeric

example; SELECT AVG (sal) “Average” FROM emple;

3. COUNT: Counts the number of rows in a given column or expression.

Syntax: COUNT ({ DISTINCT | ALL expr})

- Returns the number of rows in the query.


- if you specify argument expr, this function returns rows where expr is not null. You can count
all rows, only distinct values of expr.
3. MAX: Returns the maximum value for given column or expression.
• Syntax: Max ([ DISTINCT | ALL]) expr)

- Returns maximum value of argument expr.

- Argument type: Numeric

- Return value: Numeric

4. MIN: this function returns the minimum value from a given column or expression.

• Syntax: MIN ([ DISTINCT | ALL] expr)

- Returns minimum value of expr.

- Argument type: Numeric

- Return value: Numeric

5. SUM: This function returns the sum of values in a given column or expression.

• Syntax: SUM ([ DISTINCT | ALL] n)

- Returns sum of the values of n- parameters.

- Argument type: Numeric

- Return value: Numeric


• GROUPING RESULT: GROUP BY
the “Group by” clause combines all those records that have identical values in a particular field or a group of fields.

This grouping results into one summary record per group if group function are used with it.

i.e. THE GROUP BY command / clause is used in SELECT statements to divide the table into groups.
THANKS FOR WATCHING

You might also like