SQL Day 2
SQL Day 2
SQL Day 2
commands in Mysql
1
Contents
Data Types in MySQL....................................................................................................................4
Numeric data types in SQL..................................................................................................................................................4
Date and Time Data Types.................................................................................................................................................. 5
Character Strings Data Types............................................................................................................................................ 5
Commands in SQL.........................................................................................................................6
1. Data Definition Language (DDL):................................................................................................................................6
Creating a Database:......................................................................................................................................................... 6
Dropping a database:....................................................................................................................................................... 6
Creating a table in SQL:................................................................................................................................................... 6
Dropping a table in SQL:................................................................................................................................................. 7
SQL commands for altering a table:...........................................................................................................................7
Command to change the datatype of the column...................................................................................................7
Command for adding a new column to an existing table.................................................................................7
Command for renaming a column name.................................................................................................................8
Inserting values into the created table.....................................................................................................................8
Updating the records inside the table.......................................................................................................................8
Deleting a record inside the table:..............................................................................................................................9
2
3
Data Types in MySQL
tinyint 0 255
Bit 0 1
4
datetime Jan 1, 1753 with time Dec 31, 9999 with time
Commands in SQL
SQL commands are instructions. It is used to communicate with the database. It
is also used to perform specific tasks, functions, and queries of data.
SQL can perform various tasks like create a table, add data to tables, drop the
table, modify the table, set permission for users.
5
1. Data Definition Language (DDL):
● DDL changes the structure of the table like creating a table, deleting a table, altering a
table, etc.
● All the commands of DDL are auto-committed, which means it permanently saves all
the changes in the database.
Creating a Database:
The below syntax will help you to create a database named Innomatics.
Dropping a database:
The syntax below will let you drop a database.
Example:
Creating an employee table:
6
Dropping a table in SQL:
Example:
7
Inserting values into the created table
Syntax 1:
If in case, you are using the below syntax you must insert the values in the same order
as the columns are created.
Example:
Syntax 2:
8
Let’s update the salary for employee number 122 to 85000.
We can see that the salary for employeeNumber 122 as been changed to 85000.
We can now see that record for employeeNumber has been deleted