SlideShare ist ein Scribd-Unternehmen logo
1 von 7
Downloaden Sie, um offline zu lesen
Laboratory Activity 1
                                     MySQL Basics
Objectives
At the end of the activity, student is expected to perform the following:

          Run MySQL command line
          Display available databases
          Create database and tables
          Alter table and set up primary key
          Insert, update and delete tables

Run MySQL Command Line Prompt
We run MySQL prompt, click Start | Programs | MySQL | MySQL Server 5.1 | MySQL
Command Line Client. See Figure 1. If you are prompted with a password, type the
password that you have assigned during running of MySQL Server Instance Config Wizard
or simply hit enter from keyboard.




                     Figure 1. Launching of Command Prompt Window


Page 1 of 7                                   http://ThrivingAndLiving.blogspot.com
Figure 2 shows the mysql command prompt line . You are now on MySQL Server
environment.




                            Figure 2. MySQL command prompt

Display Available Databases

MySQL comes with default databases upon installation. These are information_schema,
mysql and test. Mysql and information_schema databases are special databases where
MySql server stores various access permissions. Test database is used for various testing
features and sample databases.

       To display all the available databases on the server we type:

              SHOW DATABASES;

       Please take note that all commands should be terminated with semicolon to signal
MySQL that a command is completed and ready for execution. Figure 3 should show the
output of the command.




                     Figure 3. Databases available currently at server


Page 2 of 7                                  http://ThrivingAndLiving.blogspot.com
Create Database
We will now create our own (new) database. Let us say that the name of our database is
my_store. Command syntax for creating database is CREATE DATABASE <database
name>. Figure 4 displays the creation of my_store database after issuing the SHOW
DATABASES command.




                          Figure 4. my_store database is created

Create Table within the Database
Database consists of table/s where we store rows and columns. Creating a database does not
mean you open it automatically. USE <database name> is the syntax in opening a database.
In order to open my_store database we issue:

       USE my_store;

       We will create now a table products to hold all products data within the database.
Our products table consists of attributes/fieldnames vital in identifying description about a
product. Syntax in creating a table has this format:

       CREATE TABLE <table name> ( <fieldname1> DATA TYPE,
                                   <fieldname2> DATA TYPE…
                                   <fieldnameN> DATA TYPE);

       Our initial table attributes for products are productID, description and unit.
We issue this command to create our first table:

       CREATE TABLE products ( productID VARCHAR(5),
       description VARCHAR(50), unit VARCHAR(3));




Page 3 of 7                                 http://ThrivingAndLiving.blogspot.com
To check the structure of products table, we use DESCRIBE <tablename> to show
its composition. Figure 5 has the output:




                                Figure 5. Creating a Table

Alter Table and Set up Primary Key

All relational database tables should have a primary key/s that will identify uniqueness of
row/record. On our products table, we will set productID as the primary key. We issue
the following command:

       ALTER TABLE products
       ADD PRIMARY KEY (productID);

        What you have noticed here is the use of ADD PRIMARY KEY command in setting
up the productID as our primary key. As we again describe the structure of our table, Figure
6 shows the output:




                     Figure 6. Setting up of productID as primary key


Page 4 of 7                                 http://ThrivingAndLiving.blogspot.com
We may even add additional columns/attributes that will further describe data for
products. Let us add column date_created on our table.

       ALTER TABLE products
       ADD date_created DATE;

       Describing the table again after the ALTER command shows on Figure 7.




                           Figure 7. Adding date_created column

The INSERT Command
The INSERT INTO statement is used to insert new rows/records into a table. After the
VALUES keyword, a comma-separated list of column names follows:

       INSERT INTO <table_name> (<column1>, <column2>….)
       VALUES (<value1, value2…);

       Let us insert and execute the following statement:

              INSERT INTO products (productID, description, unit, date_created)
              VALUES (‘PC001’, ‘Compaq laptop computer’,’ea’, ‘2009-11-23’);

       Issue another insert:

              INSERT INTO products (productID, description, unit, date_created)
              VALUES (‘PC002’, ‘Dell Desktop computer’,’ea’, ‘2009-11-22’);

        To see if the following rows were successfully added, we will use SELECT statement
to display all rows. * represents all rows.


Page 5 of 7                                 http://ThrivingAndLiving.blogspot.com
SELECT * FROM products;

       Figure 8 shows the output of the two rows insertion upon displaying it with SELECT
statement:




                  Figure 8. Display of records after a SELECT statement



Using UPDATE statement

This command is used to modify the data in the table. It has the following syntax:

          UPDATE <table_name>
          SET <column_name> = new_value
          WHERE < where condition> ;

          If we want to correct PC002’s Description to a value ‘Dell laptop computer’, our
statement will be:

              UPDATE products
              SET description =’Dell laptop computer’
              WHERE productID = ‘PC002’;

       We have used WHERE clause in the statement to qualify what data is to be modified,
thereby limiting the scope of the update.

       Again, SELECT statement is used to display changes. See Figure 9.




Page 6 of 7                                 http://ThrivingAndLiving.blogspot.com
Figure 9. Using UPDATE statement

Deleting Records from Table
The DELETE statement is used to delete rows from table and returns the number of rows
deleted. Below is the syntax that uses also a WHERE clause to identify the criteria of what
data should be removed:

       DELETE FROM <table_name>
       WHERE < where condition>;

       Let us delete productID which has a value of ‘PC001’.

              DELETE FROM products
              WHERE productID = ‘PC001’;

       We issue again a SELECT statement to see the deletion was done. Figure 10 shows
it.




                        Figure 10. Issuing a DELETE statement.



Page 7 of 7                                http://ThrivingAndLiving.blogspot.com

Weitere ähnliche Inhalte

Was ist angesagt?

SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3Dan D'Urso
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commandsBelle Wx
 
Creating Views - oracle database
Creating Views - oracle databaseCreating Views - oracle database
Creating Views - oracle databaseSalman Memon
 
Application development using Microsoft SQL Server 2000
Application development using Microsoft SQL Server 2000Application development using Microsoft SQL Server 2000
Application development using Microsoft SQL Server 2000webhostingguy
 
Subqueriesandjoins unit6
Subqueriesandjoins unit6Subqueriesandjoins unit6
Subqueriesandjoins unit6Jenip Shrestha
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands1keydata
 
Getting Started with MySQL II
Getting Started with MySQL IIGetting Started with MySQL II
Getting Started with MySQL IISankhya_Analytics
 
Step bystep abap_changinga_singlerecord
Step bystep abap_changinga_singlerecordStep bystep abap_changinga_singlerecord
Step bystep abap_changinga_singlerecordMilind Patil
 
Producing Readable Output with iSQL*Plus - Oracle Data Base
Producing Readable Output with iSQL*Plus - Oracle Data BaseProducing Readable Output with iSQL*Plus - Oracle Data Base
Producing Readable Output with iSQL*Plus - Oracle Data BaseSalman Memon
 
White paper a complete guide to oracle bi discoverer end user layer
White paper  a complete guide to oracle bi discoverer end user layerWhite paper  a complete guide to oracle bi discoverer end user layer
White paper a complete guide to oracle bi discoverer end user layerLatha Rajendran
 
Les08 (manipulating data)
Les08 (manipulating data)Les08 (manipulating data)
Les08 (manipulating data)Achmad Solichin
 

Was ist angesagt? (20)

SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
 
Sql presentation 1 by chandan
Sql presentation 1 by chandanSql presentation 1 by chandan
Sql presentation 1 by chandan
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
Dbms practical list
Dbms practical listDbms practical list
Dbms practical list
 
Creating Views - oracle database
Creating Views - oracle databaseCreating Views - oracle database
Creating Views - oracle database
 
Application development using Microsoft SQL Server 2000
Application development using Microsoft SQL Server 2000Application development using Microsoft SQL Server 2000
Application development using Microsoft SQL Server 2000
 
Subqueriesandjoins unit6
Subqueriesandjoins unit6Subqueriesandjoins unit6
Subqueriesandjoins unit6
 
Sql views
Sql viewsSql views
Sql views
 
Oracle: Basic SQL
Oracle: Basic SQLOracle: Basic SQL
Oracle: Basic SQL
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
 
Mysql cheatsheet
Mysql cheatsheetMysql cheatsheet
Mysql cheatsheet
 
Sql basics
Sql  basicsSql  basics
Sql basics
 
Getting Started with MySQL II
Getting Started with MySQL IIGetting Started with MySQL II
Getting Started with MySQL II
 
Sql ch 13 - sql-views
Sql ch 13 - sql-viewsSql ch 13 - sql-views
Sql ch 13 - sql-views
 
Step bystep abap_changinga_singlerecord
Step bystep abap_changinga_singlerecordStep bystep abap_changinga_singlerecord
Step bystep abap_changinga_singlerecord
 
Sq lite
Sq liteSq lite
Sq lite
 
Producing Readable Output with iSQL*Plus - Oracle Data Base
Producing Readable Output with iSQL*Plus - Oracle Data BaseProducing Readable Output with iSQL*Plus - Oracle Data Base
Producing Readable Output with iSQL*Plus - Oracle Data Base
 
White paper a complete guide to oracle bi discoverer end user layer
White paper  a complete guide to oracle bi discoverer end user layerWhite paper  a complete guide to oracle bi discoverer end user layer
White paper a complete guide to oracle bi discoverer end user layer
 
Les08 (manipulating data)
Les08 (manipulating data)Les08 (manipulating data)
Les08 (manipulating data)
 
Dbms lab Manual
Dbms lab ManualDbms lab Manual
Dbms lab Manual
 

Andere mochten auch

Texas Star Chart Campus Results
Texas Star Chart Campus ResultsTexas Star Chart Campus Results
Texas Star Chart Campus ResultsJana Cash
 
Button controls and using methods to make a simple web browser
Button controls and using methods to make a simple web browserButton controls and using methods to make a simple web browser
Button controls and using methods to make a simple web browserSecondary School
 
Proyecto mil senderos por recorrer
Proyecto mil senderos por recorrerProyecto mil senderos por recorrer
Proyecto mil senderos por recorrerguadalinfolataha
 
Administrative assistant ri-z
Administrative assistant ri-zAdministrative assistant ri-z
Administrative assistant ri-zRosaiqbal
 
Vigin Coconut Oil(VCO)
Vigin Coconut Oil(VCO)Vigin Coconut Oil(VCO)
Vigin Coconut Oil(VCO)Sowmya Reddy
 
C.V. David Labbé, M.Sc., agr., chm.
C.V. David Labbé, M.Sc., agr., chm.C.V. David Labbé, M.Sc., agr., chm.
C.V. David Labbé, M.Sc., agr., chm.davidlabbe
 
15.project attendence managemnt system
15.project attendence managemnt system15.project attendence managemnt system
15.project attendence managemnt systemHaseeb Nasir
 

Andere mochten auch (15)

Mil senderos por recorrer
Mil senderos por recorrerMil senderos por recorrer
Mil senderos por recorrer
 
Texas Star Chart Campus Results
Texas Star Chart Campus ResultsTexas Star Chart Campus Results
Texas Star Chart Campus Results
 
งานนำเสนอ1
งานนำเสนอ1งานนำเสนอ1
งานนำเสนอ1
 
Button controls and using methods to make a simple web browser
Button controls and using methods to make a simple web browserButton controls and using methods to make a simple web browser
Button controls and using methods to make a simple web browser
 
Introduction to computing
Introduction to computingIntroduction to computing
Introduction to computing
 
Extending the web browser
Extending the web browserExtending the web browser
Extending the web browser
 
Dooms day
Dooms dayDooms day
Dooms day
 
Virtualidad
VirtualidadVirtualidad
Virtualidad
 
Proyecto mil senderos por recorrer
Proyecto mil senderos por recorrerProyecto mil senderos por recorrer
Proyecto mil senderos por recorrer
 
Administrative assistant ri-z
Administrative assistant ri-zAdministrative assistant ri-z
Administrative assistant ri-z
 
Microbial fuel cell
Microbial fuel cellMicrobial fuel cell
Microbial fuel cell
 
Coco Sugar
Coco SugarCoco Sugar
Coco Sugar
 
Vigin Coconut Oil(VCO)
Vigin Coconut Oil(VCO)Vigin Coconut Oil(VCO)
Vigin Coconut Oil(VCO)
 
C.V. David Labbé, M.Sc., agr., chm.
C.V. David Labbé, M.Sc., agr., chm.C.V. David Labbé, M.Sc., agr., chm.
C.V. David Labbé, M.Sc., agr., chm.
 
15.project attendence managemnt system
15.project attendence managemnt system15.project attendence managemnt system
15.project attendence managemnt system
 

Ähnlich wie mysql 1st. act.

Ähnlich wie mysql 1st. act. (20)

chapter 8 SQL.ppt
chapter 8 SQL.pptchapter 8 SQL.ppt
chapter 8 SQL.ppt
 
Chap 7
Chap 7Chap 7
Chap 7
 
chap 7.ppt(sql).ppt
chap 7.ppt(sql).pptchap 7.ppt(sql).ppt
chap 7.ppt(sql).ppt
 
Using Mysql.pptx
Using Mysql.pptxUsing Mysql.pptx
Using Mysql.pptx
 
Mysql
MysqlMysql
Mysql
 
MySQL
MySQLMySQL
MySQL
 
SQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptxSQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptx
 
Getting Started with MySQL I
Getting Started with MySQL IGetting Started with MySQL I
Getting Started with MySQL I
 
MySQL and its basic commands
MySQL and its basic commandsMySQL and its basic commands
MySQL and its basic commands
 
mysqlanditsbasiccommands-150226033905-conversion-gate02.pdf
mysqlanditsbasiccommands-150226033905-conversion-gate02.pdfmysqlanditsbasiccommands-150226033905-conversion-gate02.pdf
mysqlanditsbasiccommands-150226033905-conversion-gate02.pdf
 
Les10
Les10Les10
Les10
 
Introduction to Oracle Database.pptx
Introduction to Oracle Database.pptxIntroduction to Oracle Database.pptx
Introduction to Oracle Database.pptx
 
Oracle: Commands
Oracle: CommandsOracle: Commands
Oracle: Commands
 
Oracle: DDL
Oracle: DDLOracle: DDL
Oracle: DDL
 
My sql with querys
My sql with querysMy sql with querys
My sql with querys
 
MySQL Presentation
MySQL PresentationMySQL Presentation
MySQL Presentation
 
Ch 9 S Q L
Ch 9  S Q LCh 9  S Q L
Ch 9 S Q L
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 
DOODB_LAB.pptx
DOODB_LAB.pptxDOODB_LAB.pptx
DOODB_LAB.pptx
 

Kürzlich hochgeladen

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 

Kürzlich hochgeladen (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

mysql 1st. act.

  • 1. Laboratory Activity 1 MySQL Basics Objectives At the end of the activity, student is expected to perform the following:  Run MySQL command line  Display available databases  Create database and tables  Alter table and set up primary key  Insert, update and delete tables Run MySQL Command Line Prompt We run MySQL prompt, click Start | Programs | MySQL | MySQL Server 5.1 | MySQL Command Line Client. See Figure 1. If you are prompted with a password, type the password that you have assigned during running of MySQL Server Instance Config Wizard or simply hit enter from keyboard. Figure 1. Launching of Command Prompt Window Page 1 of 7 http://ThrivingAndLiving.blogspot.com
  • 2. Figure 2 shows the mysql command prompt line . You are now on MySQL Server environment. Figure 2. MySQL command prompt Display Available Databases MySQL comes with default databases upon installation. These are information_schema, mysql and test. Mysql and information_schema databases are special databases where MySql server stores various access permissions. Test database is used for various testing features and sample databases. To display all the available databases on the server we type: SHOW DATABASES; Please take note that all commands should be terminated with semicolon to signal MySQL that a command is completed and ready for execution. Figure 3 should show the output of the command. Figure 3. Databases available currently at server Page 2 of 7 http://ThrivingAndLiving.blogspot.com
  • 3. Create Database We will now create our own (new) database. Let us say that the name of our database is my_store. Command syntax for creating database is CREATE DATABASE <database name>. Figure 4 displays the creation of my_store database after issuing the SHOW DATABASES command. Figure 4. my_store database is created Create Table within the Database Database consists of table/s where we store rows and columns. Creating a database does not mean you open it automatically. USE <database name> is the syntax in opening a database. In order to open my_store database we issue: USE my_store; We will create now a table products to hold all products data within the database. Our products table consists of attributes/fieldnames vital in identifying description about a product. Syntax in creating a table has this format: CREATE TABLE <table name> ( <fieldname1> DATA TYPE, <fieldname2> DATA TYPE… <fieldnameN> DATA TYPE); Our initial table attributes for products are productID, description and unit. We issue this command to create our first table: CREATE TABLE products ( productID VARCHAR(5), description VARCHAR(50), unit VARCHAR(3)); Page 3 of 7 http://ThrivingAndLiving.blogspot.com
  • 4. To check the structure of products table, we use DESCRIBE <tablename> to show its composition. Figure 5 has the output: Figure 5. Creating a Table Alter Table and Set up Primary Key All relational database tables should have a primary key/s that will identify uniqueness of row/record. On our products table, we will set productID as the primary key. We issue the following command: ALTER TABLE products ADD PRIMARY KEY (productID); What you have noticed here is the use of ADD PRIMARY KEY command in setting up the productID as our primary key. As we again describe the structure of our table, Figure 6 shows the output: Figure 6. Setting up of productID as primary key Page 4 of 7 http://ThrivingAndLiving.blogspot.com
  • 5. We may even add additional columns/attributes that will further describe data for products. Let us add column date_created on our table. ALTER TABLE products ADD date_created DATE; Describing the table again after the ALTER command shows on Figure 7. Figure 7. Adding date_created column The INSERT Command The INSERT INTO statement is used to insert new rows/records into a table. After the VALUES keyword, a comma-separated list of column names follows: INSERT INTO <table_name> (<column1>, <column2>….) VALUES (<value1, value2…); Let us insert and execute the following statement: INSERT INTO products (productID, description, unit, date_created) VALUES (‘PC001’, ‘Compaq laptop computer’,’ea’, ‘2009-11-23’); Issue another insert: INSERT INTO products (productID, description, unit, date_created) VALUES (‘PC002’, ‘Dell Desktop computer’,’ea’, ‘2009-11-22’); To see if the following rows were successfully added, we will use SELECT statement to display all rows. * represents all rows. Page 5 of 7 http://ThrivingAndLiving.blogspot.com
  • 6. SELECT * FROM products; Figure 8 shows the output of the two rows insertion upon displaying it with SELECT statement: Figure 8. Display of records after a SELECT statement Using UPDATE statement This command is used to modify the data in the table. It has the following syntax: UPDATE <table_name> SET <column_name> = new_value WHERE < where condition> ; If we want to correct PC002’s Description to a value ‘Dell laptop computer’, our statement will be: UPDATE products SET description =’Dell laptop computer’ WHERE productID = ‘PC002’; We have used WHERE clause in the statement to qualify what data is to be modified, thereby limiting the scope of the update. Again, SELECT statement is used to display changes. See Figure 9. Page 6 of 7 http://ThrivingAndLiving.blogspot.com
  • 7. Figure 9. Using UPDATE statement Deleting Records from Table The DELETE statement is used to delete rows from table and returns the number of rows deleted. Below is the syntax that uses also a WHERE clause to identify the criteria of what data should be removed: DELETE FROM <table_name> WHERE < where condition>; Let us delete productID which has a value of ‘PC001’. DELETE FROM products WHERE productID = ‘PC001’; We issue again a SELECT statement to see the deletion was done. Figure 10 shows it. Figure 10. Issuing a DELETE statement. Page 7 of 7 http://ThrivingAndLiving.blogspot.com