Download presentation
Presentation is loading. Please wait.
Published byCarol Porter Modified over 9 years ago
1
>> Introduction to MySQL
2
Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System) MySQL, Oracle, MS SQL Server Web-Based Systems | Misbhauddin 2
3
Databases Database – Stores data for fast and efficient access – Structured into tables Web-Based Systems | Misbhauddin 3 NameIDMajorGPA Abdur Rahman312456CIS3.97 Ahmed312198CS4.00 Mohammed312786CIS2.78 Rows Columns Record Field
4
MySQL Fast, Reliable, Easy-to-use Multi-user Freely available Network Database of choice (used mostly with PHP) – Connectivity – Speed – Security Web-Based Systems | Misbhauddin 4
5
Getting Started Operations on a DBMS (CRUD) – Create – Retrieve – Update – Delete Target – Databases – Tables – Records Web-Based Systems | Misbhauddin 5 Note: SQL is not case sensitive
6
CREATE Web-Based Systems | Misbhauddin 6
7
Create Database Using a database Web-Based Systems | Misbhauddin 7 CRUD DTR Create a new DB called MyDB Use that database TRY NOW SYNTAX CREATE DATABASE Database_Name; USE Database_Name;
8
Primary Key Web-Based Systems | Misbhauddin 8 PRIMARY KEY uniquely identifies each record in a database table must contain unique values cannot contain NULL each table should have a primary key each table can have only ONE primary key
9
Create Table Web-Based Systems | Misbhauddin 9 CRUD DTR SYNTAX CREATE TABLE Table_Name (column_specifications); For each column Name of the column Data type Size Other constraints int (signed, unsigned) double, float char, varchar text blob date, time, datetime Student_IDNameMajorGPA Create Table students( Student_ID int unsigned, Name varchar(50), Major varchar(3), GPA float, PRIMARY KEY(Student_ID)); TRY NOW NOT NULL UNIQUE CHECK DEFAULT
10
Insert Record Web-Based Systems | Misbhauddin 10 CRUD DTR SYNTAX INSERT INTO table_name SET col_name1=value1, col_name2=value2, col_name3=value3, … OR Student_IDNameMajorGPA 312981MohammedCIS4.00 TRY NOW INSERT INTO table_name (col_name1, col_name2) VALUES (value1, value2); Note: Strings in ‘ ‘(single quotes)
11
RETRIEVE Web-Based Systems | Misbhauddin 11
12
Retrieve Database Listing Existing Databases – show databases; Web-Based Systems | Misbhauddin 12 CRUD DTR Show databases; TRY NOW
13
Retrieve Table Using a Database – use db-name ; Listing Tables in a Database – show tables; Table Structure – describe table-name; Web-Based Systems | Misbhauddin 13 CRUD DTR Look at the table you created TRY NOW
14
Retrieve Record Web-Based Systems | Misbhauddin 14 CRUD DTR SYNTAX SELECT column_name(s) FROM table_name Using * here will select all columns TRY NOW
15
Retrieve Record Web-Based Systems | Misbhauddin 15 CRUD DTR SELECT SELECT column_name(s) FROM table_name DISTINCT (Return only unique values) WHERE column_name operator value OperatorDescription =Equal !=Not equal >Greater than <Less than >=Greater than or equal <=Less than or equal BETWEENBetween an inclusive range LIKESearch for a pattern INTo specify multiple possible values for a column AND column_name2 operator value2 OR column_name2 operator value2 ORDER BY column_name(s) ASC|DESC
16
UPDATE Web-Based Systems | Misbhauddin 16
17
Update Database Can only rename a Database Can be done from the DBMS (outside the SQL) Other way – Create new database (with new name) – Make dump of old database – Import dumped data into new database – Delete old database Web-Based Systems | Misbhauddin 17 CRUD DTR
18
Alter Table Web-Based Systems | Misbhauddin 18 CRUD DTR 1.Add a new column “DOB” with type date 2.Change the new column’s datatype to year 3.Delete Column GPA TRY NOW SYNTAX ALTER TABLE table_name ADD column_name datatype MODIFY column_name datatype DROP COLUMN column_name OR
19
Update Record Web-Based Systems | Misbhauddin 19 CRUD DTR SYNTAX UPDATE table_name SET column1=value1, column2=value2,... WHERE column=value; Remember Choose a unique (or Primary Key) here else multiple rows will be updated TRY NOW Student_IDNameMajorDOB 312981MohammedCIS Add “1990” here
20
DELETE Web-Based Systems | Misbhauddin 20
21
Delete Record Web-Based Systems | Misbhauddin 21 CRUD DTR SYNTAX DELETE FROM table_name WHERE column=value; Delete this record TRY NOW Student_IDNameMajorDOB 312981MohammedCIS1990 Note: Remove this to delete all rows.
22
Drop Table Web-Based Systems | Misbhauddin 22 CRUD DTR Drop the created table TRY NOW SYNTAX DROP TABLE Table_Name;
23
Drop Database Web-Based Systems | Misbhauddin 23 CRUD DTR Drop the created database TRY NOW SYNTAX DROP DATABASE Database_Name;
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.