On MYSQL COMMANDS
On MYSQL COMMANDS
JYOTIPURAM
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.
CREATE TABLE < table name >(<column more> <data type>)[(size)](<column name> <data types>)[(<size>)……..]
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.
• The UPDATE command specifies the rows to be changed using the WHERE clause and the new data using the SET
KEYWORD.
• Delete command removes rows from a table i.e. this removes entire rows not individual field values.
• 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.
• Syntax: ALTER TABLE <table name> ADD <column name> <data type> <size>;
• ALTER TABLE <table name> MODIFY (column name new data type(new size)) [FIRST | AFTER column];
DROPPING TABLES:
The drop table command of SQL is used to drop a table from the database.
• The [IF EXISTS] clause of Drop table first checks whether the given table exists in the database or not.
• 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],…..]
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.
4. MIN: this function returns the minimum value from a given column or expression.
5. SUM: This function returns the sum of values in a given column or expression.
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