Professional Documents
Culture Documents
Unit 2
MySQL
• Initial release 23 May 1995
• Latest Version 8.0.23 / 18 January 2021
• Written in C, C++
• Operating Systems: Solaris, mac, Windows ..
• Type: RDBMS
MySQL Commands
MySQL Data Types
Syntax:
Select * from table_name
Example:
Select * from tasks
Describe Table
• To view the structure / schema of a table
Syntax:
• DESCRIBE table_name
• DESC table_name
Example:
Delete
• To delete the contents of the table
Syntax:
DELETE * FROM table_name
DELETE FROM table_name WHERE condition
Example:
DELETE * FROM tasks
DELETE * FROM tasks WHERE task_id=1
Update
• To update a value in table
Syntax:
• UPDATE table_name SET field1 = new-value1,
field2 = new-value2 [WHERE Clause]
Example:
• UPDATE tasks SET task_name=‘xyz’ WHERE
task_id=1
Example
create table tutorials_tbl
( tutorial_id INT NOT NULL AUTO_INCREMENT,
tutorial_title VARCHAR(100) NOT NULL,
tutorial_author VARCHAR(40) NOT NULL,
submission_date DATE,
PRIMARY KEY ( tutorial_id )
);
Sorting Results
Syntax:
• SELECT field1, field2,...fieldN FROM
table_name1 ORDER BY field1, [field2...] [ASC
[DESC]]
Example:
ALTER
• ALTER TABLE table_name
ADD column_name datatype;
• ALTER TABLE table_name
DROP COLUMN column_name;
• ALTER TABLE table_name
ALTER COLUMN column_name datatype;
• ALTER TABLE Persons
ADD PRIMARY KEY (ID);
RENAME
• RENAME TABLE old_table_name TO
new_table_name;
• RENAME DATABASE old_db_name TO new_db
_name;