Presentation is loading. Please wait.

Presentation is loading. Please wait.

Day 3 - Basics of MySQL What is MySQL What is MySQL How to make basic tables How to make basic tables Simple MySQL commands. Simple MySQL commands.

Similar presentations


Presentation on theme: "Day 3 - Basics of MySQL What is MySQL What is MySQL How to make basic tables How to make basic tables Simple MySQL commands. Simple MySQL commands."— Presentation transcript:

1 Day 3 - Basics of MySQL What is MySQL What is MySQL How to make basic tables How to make basic tables Simple MySQL commands. Simple MySQL commands.

2 CSE 498Day 3 - Basics of MySQL2 / 8 What is MySQL? MySQL is a true multi-user, multi-threaded SQL database server. SQL is the most popular relational database in the world. MySQL is a true multi-user, multi-threaded SQL database server. SQL is the most popular relational database in the world. Goals of system: Goals of system: –Client/server implementation of a relational database system. –Speed of transactions and queries going through. –Robustness of the system. –Easy to use and learn. –Be able to handle large systems easily and quickly.

3 CSE 498Day 3 - Basics of MySQL3 / 8 Relational DB Relational DB –A relational database is the reality of a E/R diagram model. It uses the basic parts of the E/R diagram and enforces them in a database. Basic Parts Basic Parts –Keys & Attributes are the same –Table: Entity relation of a E/R diagram. –Record: An instance of a row of data in a table. What is a relational database?

4 CSE 498Day 3 - Basics of MySQL4 / 8 Data Types & Basics Data Types Data Types –Integers: TinyInt, SmallInt, MediumInt, Int, BigInt –Real Numbers: Float, Double, Decimal, Real –Time: Date, DateTime, Timestamp, Time, Year (Y2K Compliant) –String: Char, VarChar –Text: TinyText, MediumText, LongText Basic MySQL Commands Basic MySQL Commands –Note: All commands/queries end with a semi-colon. –show tables; Command will show you the name of all the tables currently in the DB.Command will show you the name of all the tables currently in the DB. – desc ; Command will show you information about the requested table.Command will show you information about the requested table.

5 CSE 498Day 3 - Basics of MySQL5 / 8 CREATE TABLE command Command for creating a table in the DB Command for creating a table in the DB –CREATE TABLE table_name (attribute definition, …) –attribute definition : column_name data_type (options) –options : NOT NULL/NULL, AUTO INCREMENT, PRIMARY KEY, DEFAULT default_value, PRIMARY KEY, DEFAULT default_value, (reference_definition) (reference_definition) –reference_definition : REFERENCE table_name (column_name, …) MATCH FULL/MATCH PARTIAL MATCH FULL/MATCH PARTIAL Example: Category table from Day 2 Example: Category table from Day 2 > CREATE TABLE category (cat_id INT NOT NULL PRIMARY KEY, cat_name var_char NOT NULL); > CREATE TABLE category (cat_id INT NOT NULL PRIMARY KEY, cat_name var_char NOT NULL);

6 CSE 498Day 3 - Basics of MySQL6 / 8 ALTER TABLE & DROP TABLE Command ALTER TABLE - Used to change a table. ALTER TABLE - Used to change a table. –ALTER TABLE table_name (alter_spec) –Three basic alter_specs: ADD : Used to add a column, index specification, or primary key specificationADD : Used to add a column, index specification, or primary key specification CHANGE: Used to change a column specification in the tableCHANGE: Used to change a column specification in the table DROP: Used to drop a column from the table.DROP: Used to drop a column from the table. –Example: Add a column to the category table. > ALTER TABLE category ADD cat_alias var_char NULL; > ALTER TABLE category ADD cat_alias var_char NULL; DROP TABLE - Used to delete a table. DROP TABLE - Used to delete a table. –DROP TABLE table_name –Note: Be careful with this one because once it’s gone, it’s gone.

7 CSE 498Day 3 - Basics of MySQL7 / 8 Used to insert data into tables. Used to insert data into tables. Format Format –INSERT INTO table_name (col_name, …) VALUES (expression, …), (expression, …), … Example: Insert info into the category table… Example: Insert info into the category table… > INSERT INTO category (cat_id, cat_name) VALUES (1, “Action/Adventure”); > INSERT INTO category (cat_id, cat_name) VALUES (1, “Action/Adventure”); Insert Command

8 CSE 498Day 3 - Basics of MySQL8 / 8 DELETE & UPDATE Commands Both commands use a query format to run the command on the data in a table. Queries are explained in the next set of slides. Both commands use a query format to run the command on the data in a table. Queries are explained in the next set of slides. DELETE - Used to delete information from a table. DELETE - Used to delete information from a table. –DELETE FROM table_name WHERE (rule) –Example: Delete the ‘oldies’ category from the table. > DELETE FROM category WHERE cat_name = “Oldies”; UPDATE - Used to update table information. UPDATE - Used to update table information. –UPDATE table_name SET col_name = expression WHERE (rule) –Example: Change category “Scary Movies” to “Horror” > UPDATE category SET cat_name = “Horror” WHERE cat_name = “Scary Movies”;


Download ppt "Day 3 - Basics of MySQL What is MySQL What is MySQL How to make basic tables How to make basic tables Simple MySQL commands. Simple MySQL commands."

Similar presentations


Ads by Google