0% found this document useful (0 votes)
24 views3 pages

Mysql Class 12 SN

This document provides a comprehensive overview of basic MySQL commands, data types, constraints, and operators. It covers essential commands for database management, including how to show databases, insert data, and modify tables, as well as details on data types like strings, numerics, and date/time formats. Additionally, it explains various constraints, drop statements, and SQL operators for querying data effectively.

Uploaded by

pranavrao168
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)
24 views3 pages

Mysql Class 12 SN

This document provides a comprehensive overview of basic MySQL commands, data types, constraints, and operators. It covers essential commands for database management, including how to show databases, insert data, and modify tables, as well as details on data types like strings, numerics, and date/time formats. Additionally, it explains various constraints, drop statements, and SQL operators for querying data effectively.

Uploaded by

pranavrao168
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/ 3

MySQL Short Notes

13 July 2023 21:29

*Commands in MYSQL are case INSENSITIVE

Commands In MYSQL (Basic Commands):


1. Show databases;
2. Use <database_name>;
The preferred database will be used and everything can be modified only in the database that has been
chose.
Shows the existing databases present in the system.
3. Show tables;
Shows the respective tables present in database.
4. Desc <table_name>;
Displays the columns of the database and column description.
5. Select * from <table_name>;
Displays the table as it is.
6. Insert into <table_name> values(<Enter data1>),(<Enter data2>)….;
Helps in inserting values into the table, each entry has to be a tuple followed by a comma.

Datatypes: Each column in a database table is required to have a name and a data type.
• String
• Numeric
• Date & Time

String:
• Char(size): A fixed length string (can contain letters ,numbers and special characters). The size parameter
specifies the column length in characters. Can be from 0-255. Default is 1.
• Varchar(size): A variable length string(can contain letters ,numbers and special characters). The size
parameter specifies the column length in characters. Can be from 0-255/65535. Default is 1.
• Binary(size): Equal to char(), but stores binary byte strings. The size parameter specifies the column length
in bytes. Default is 1.
• Blob(size): For BLOBs (Binary Large Objects). It holds up to 65535 bytes of data.

Numeric:
• INT(size): Signed range is from 2147483648 to 2147483647. Unsigned range is from 0 to 4294967295. The
size parameter specifies the maximum display width(which is 255).
• Integer(size): Same as INT(size)
• Float(size,decimal): A floating point number. The total number of digits is specified in size, the number of
digits after the decimal point is specified in the decimal parameter.
• Double(size,decimal): A floating point number. The total number of digits is specified in size, the number of
digits after the decimal point is specified in the decimal parameter.

Date and Time:


• "yyyy/mm/dd": The date in MySQL is entered in this format.
• "HH:MM:SS": The time in MYSQL is entered in this format.

Constraints:
• Constrains are the certain type of restrictions on data value that an attribute can have.
• They are used to ensure correctness of data.
• However it is not mandatory to define a constraint for each attribute of a table.

MySQL Page 1
• However it is not mandatory to define a constraint for each attribute of a table.
Some constraints are below -
• NOT NULL: To ensure the column does not have any null values.
• Unique: To ensure the values are not repeated in a column.
• Default: A default value will be set when no entries are made.
• PRIMARY KEY
• FOREIGN KEY

Drop Statements:
• Drop table if exists <table_name>;
The above command deletes the table from the database.

• Alter table <table_name> Drop column <column_name>;


The above command deletes certain specified columns from the table.

Altering Command to add PRIMARY KEY:


• Alter table <table_name> Modify <column_name> <column_definition>;
The above command can be used to modify a specified column and its definition.

Altering Command to add new column:


• Alter table <table_name> add <new_column_name> <column_definition>;
The above code can used to add a new column in the existing table.

Delete:
• Delete from <table_name> where <condition>;
Deletes the entry from the table for the specified condition.
• Delete from <table_name>;
All values can be removed using the above command.

Update:
• Update <table_name> set column1 = value1, column2 =value2 where <condition>;
The above commands updates the values of column where the condition is specified.

Order By Clause:
The names can be arranged in descending alphabetical order using the select statement.
If ORDER BY is given without a value then it is arranged in ascending value as default. Descending keyword is Desc
and for ascending is Asc.
• Select * from <table_name> Order by <column_name> desc;
This is display everything from the table given with the names in ascending order.

Operators:
• Arithmetic
• Relational
• Logical
• Uncategorized (Between,And,In)

Between:
• Select <column_name> from <table_name> where <column_name> between <value1> and <value2>;
The above commands displays the value from the column between the specified values.
Not Between:
• Select <column_name> from <table_name> where <column_name> not between <value1> and <value2>;
This command displays values which DO NOT lie between the specified values.

MySQL Page 2
In:
• Select * from <table_name> where <column_name> in (value1,value2…);
This shows the table with the only values specified.
Not In:
• Select * from <table_name> where <column_name> not in (value1,value2…);
• This shows all the values from the table except the values that are specified.

And:
• Select * from <table_name> where <condition1> and <condition2>;
This command shows the table for which both the conditions are met.

Not Operator:
• Select <column1>,<column2> from <table_name> where not <condition>;
This shows all the values except where the not condition is met.
Like Operator:
The two wild card operator : % and __ which will be used along with like.
% sign is used to search for 0 or more characters that look like the given pattern.
__ sign is used to search specifically for one number or character.
Example: Select * from teachers where name like '%a';
This will show all teachers name ending with a.

Column Alias:
It is a temporary name/label given to the column that will appear in the output.
• <column_name > as <column_alias>;
Ex: select adno, name, p+c+m as total from students;
This will change p+c+m as total.

Distinct:
• Select Distinct <column_name> from <table_name>;
Displays uniquely entered values in a database.

MySQL Page 3

You might also like