You are on page 1of 6

Prequel assignment for fruit command .

sql assignment

Background:
Basic Sql commands:
3 types of commands on sql
data manipulation - create, insert, delete, & update
-create table or database, insert data into table, delete row in table, update to change existing table
top-level - use, drop, & describe
- use to select database, describe to describe contents of table in terms of format and names, drop is
used to drop an entire table.
internal functions -
Now-current time, sum --sums set of values
Select- display data
-used to query and displaying data in database
-Meaningful display you must combine tables and apply functions.

Desriptive query --displays data in the table

msql functions are case insensitive ---
functions on mysql - max, sum etc... similar to excel

sTring Functions continued
Ucase ("Tomatoe") -- > TOMATOE
Lcase("tomAToe") --> tomatoe

Length (string)
-returns length ("12345")
-select length (name) =>

Locate (needle, haystack, [offset]);
returns starting index of needle in haystack.
-Select locate ("mat", "tomatoe"); > 3
-select Locate ('t', 'tomatoe', 2); > 5
select locate ('a', name) from fruit; ----> kick back starting location of A in fruit.name
select now ();--returns date

Combining Tables
- Select field from table 1, table2, .... whereI limitI order by
- each rowof table 1 is matched to each row of table 2;
> #rows = count Table 1* count Table 2
- Trick Write coinditional to Combine Tables
> where fruit.fruitID =inventory.fruitID

Goal --list all fruit names, price, sum quantity
- Select * from fruit, inventory;
- select (

Special Conditional - combined tables
-list all fruit with single inventory line with quantify over 400
* combine tables matchign fruitID

2 Logical Operators
'AND', & 'OR'
-select * from fruit where price>=1.0 price <=4.0;
************************
COMBINING MULTIPLE TABLES
select*from tbl1, tbl2, tbl3
where tb1.id=tbl2.id and tbl2.part=tbl3.part and xxx=tbl.xxx;
---->> Easier way to understand the complexity of the preceding example is to do a
SUB-QUERY (QUERY STATEMENT WITHIN A QUERY) :
select ( from table1, table2
where table1.id=table2.id
and xxx = (select xxx from table3 where condition);
0r
Select * from inventory
where fruitID=(select fruitID from fruit where name ="apple");

---------------------------------------
fruitcmds.sql
execute each command one at time
analyze output
comment on each output
submit fruitcmds.sql ---add comments which may span more than one line with # at beginning
--keypoint summary
-edit msql client using arrow keys we
-putty -terminal connection to CIM
-submit assignmentName.sql .....submit assignmentfruitcommand.sql...
submit assignmetfruitcmd.sql
-----------------------
source .sql ...(implements commands one at a time)

in mysql

submit nameoffile.sql
------------------------------------------------------------------------------------------------
php myadmin notes
sql - structured query language
- de facto standard for "communicatingto RDBMS, can both quesiton RDBMS and modify the data.
- Relational Database Manager System - DB relations between and amongtables.

4 ways to communicate into a DBmysql
-msql command prompt
- gui tools
- scripting/programming language
- web-browwer - PHPMyAdmin - works with mysql database
-> command Prompt ; mysql -u SBusername -p
-> PHPMyAdmin
* http://cim.saddleback.edu/phpmyadmin
- OS php tool for administrating MysQL
- Great at Creating DB/Tables & Basic Queries
- Automatically Generates the PHP code

Select field from table:
---- Select * from fruit;
* -wild card that outputs all field
conditional statment: from, where
--helps selects information that meets conditions of from and where
limit --- select* from fruit limit 5; (limits top 5 rows)
order by --- sorts selected information according to the order by condition

Modify database contents :
insert : insert into table values ('tom), ('dawn');
delete: delete from table {where I limit l order by];
update: update tblname set name = "tom" [w l L l o]
Create table tblName (fieldnames field types (), ]
3 main data type categories in field types: number, date and time, string
number: standard number like an interger or a floating number with number of digits before and after
decimal point.
date & time : date yyyy-mm-dd; datetime yyy-mm-dd hh:mm:ss
year(2), year(4), timestamp - Unix time stamp no hyphens
String: data that can have specific lenght such as char(length) or it has variable length
varchar(length).
or a Blob...which is a large binary object, this is used to store images
blob & text 216 , longblob 232, tinytext 28.



*** Create, edit, import, update tables ...

-

You might also like