Presentation is loading. Please wait.

Presentation is loading. Please wait.

What’s a database? Data stored in a structured format that lends itself to easy manipulation and recall.

Similar presentations


Presentation on theme: "What’s a database? Data stored in a structured format that lends itself to easy manipulation and recall."— Presentation transcript:

1 What’s a database? Data stored in a structured format that lends itself to easy manipulation and recall

2 Where it gets interesting… In a database, tables can be linked: Tables, columns, rows, “keys”, joins

3 What is SQL? A standard language for accessing databases SELECT P_id, FirstName, LastName, Age FROM tbl_people WHERE Age > 18 ORDER BY LastName An underlying language used by Relational Database Management System’s (RDBMS) such as MySQL, MS SQL Server, Oracle, Microsoft Access Note: SQL is NOT case senSiTive SQL Statement

4 Data types Describe type of data (text, numeric, date/time, binary) Depends on RDBMS Size matters! (for performance) See http://www.w3schools.com/sql/sql_datatype s.asp http://www.w3schools.com/sql/sql_datatype s.asp

5 Practice Time

6 Injecting Malicious Data submit query = “SELECT Username, UserID, Password FROM Users WHERE Username = 'bob‘; DROP Users-- ‘AND Password = ‘‘”

7

8 xkcd.com

9 Setting up database on your virtual server On the virtual server, log into mysql: []$ mysql –u root Now, you’re in mysql. Note the cursor. Create the database: > Create database mgbbase; Set it up for a particular user: > Grant all privileges on mgbbase.* to mbailey@localhost identified by ‘password’;

10 Working with a database []$ mysql –u mbailey –p mgbbase Now, at the > prompt, you can proceed to make new tables and manipulate data within them using ‘queries’

11 Setting up table create table assessment ( fullName varchar(20), idNum int not null primary key, year varchar(10), grade char(2), explaination text, graduates char(3), ta char(3), outtaHere char(3));

12 Other useful queries insert into table (column1, column2,…) values (value1, value2,…); select columns from table [where column = value]; update table set column=value [where column=value [and/or …]]; delete from table where column=value [and/or …]; Note that: ‘=‘ can be ‘ ’, etc, or can be LIKE, allowing wildcards

13 More queries Set password: update user set Password=password('NewPw') where User='root'; flush privileges; List tables: show tables; List fields in a table: show columns from xxx ;

14 Relational Database Terminology *Table=Relation; Column=Attribute; Row=Tuple Keys make tuples unique in relation SQL –Select (columns) from (tables) where (attribute value tests); –Returns a new table –Select * from person; Returns entire contents of table “person” –Select * from person where name=“Johnson” Returns a table with all columns and all rows with name==Johnson *Know these!


Download ppt "What’s a database? Data stored in a structured format that lends itself to easy manipulation and recall."

Similar presentations


Ads by Google