MySQLforBeginners (1stEdition)
ByGaneshBagaria
AbouttheAuthorGaneshBagariawasbornonDecember15,1997inNawalgarhCity,Rajasthan,India.Heisastudent,authon,ownerofhttp://worldfreeapps.comwebsite.Thisishisfirstbook.Ganeshhasmadewebsitehttp://worldfreeapps.comfordownloadingappsandgamesforAndroid,Iphone,WindowsPhone,fordownloadingSongsandforPlayingOnlineGamesforfree.YoucanconnecttoGaneshBagariaviaTwitterathttps://twitter.com/@ganeshbagaria,viaLinkedInhttps://in.linkedin.com/in/ganeshbagaria.ThisisGaneshBagaria’sfirstbooksosorryforanymistakes.
Contents▬▬▬▬▬▬▬▬▬▬▬▬▬▬Introduction……………………………………………………1Part1:CreatingDatabases,Tables………………3
CreateDatabaseCreateTableSetPrimaryKeyinTableCreationSetForeignKeyinTableCreationSetdefaultvalueincreatetable
Part2:AccessingDatabases…………………………7UseDatabase
Part3:InsertingdataintoTable………………8
InsertdataintoTableInsertNullValues
Part4:AlteringTable……………………………10AddColumn,PrimaryKeyDeleteColumn,PrimaryKey,Row,Table,DatabaseModifyTable
Part5:SelectQueries………………………………14FormatofSelectQuerySelectQueries
Part6:MySQLFunctions…………………………20StringFunctionsNumericFunctions
Part7:MySQLJoin………………………………26MySQLJoinDifferentMySQLJoins
Part8:MySQLCreateIndex…………………29CreateIndexCreateUniqueIndexDeleteIndex
Part9:MySQLAutoIncrementafield…31AddAutoIncrementinafieldinTable
Part10:MySQLView………………………………32CreateViewReplaceViewDropView
Part11:MySQLReference………………………34Part12:AboutMySQL…………………………38
IntroductionMySQLis(asofJuly2013)theworld’ssecondmost[a]widelyusedrelationaldatabasemanagementsystem(RDBMS)andmostwidelyusedopen-sourceRDBMS.Itisnamedafterco-founderMichaelWidenius’sdaughter,My.TheSQLacronymstandsforStructuredQueryLanguage.
TheMySQLdevelopmentprojecthasmadeitssourcecodeavailableunderthetermsoftheGNUGeneralPublicLicense,aswellasunderavarietyofproprietaryagreements.MySQLwasownedandsponsoredbyasinglefor-profitfirm,theSwedishcompanyMySQLAB,nowownedbyOracleCorporation.Forproprietaryuse,severalpaideditionsareavailable,andofferadditionalfunctionality.
MySQLisapopularchoiceofdatabaseforuseinwebapplications,andisacentralcomponentofthewidely usedLAMPopensourcewebapplicationsoftwarestack(andother‘AMP’stacks).LAMPisanacronymfor“Linux,Apache,MySQL,Perl/PHP/Python.”Free-software-opensourceprojectsthatrequireafull-featureddatabasemanagementsystemoftenuseMySQL.
ApplicationswhichuseMySQLdatabasesinclude:TYPO3,MODx,Joomla,
WordPress,phpBB,MyBB,Drupalandothersoftware.MySQLisalsousedin manyhigh-profile,large-scale
2
websites,includingGoogle(thoughnotforsearches),Facebook,Twitter,Flickr,andYouTube.
MySQLshipswithnoGUItoolstoadministerMySQLdatabasesormanagedatacontainedwithinthedatabases.Usersmayusetheincludedcommandlinetools,oruseMySQL“front-ends”,desktopsoftwareandwebapplicationsthatcreateandmanageMySQLdatabases,builddatabasestructures,backupdata,inspectstatus,andworkwithdatarecords.TheofficialsetofMySQLfront-endtools,MySQLWorkbenchisactivelydevelopedbyOracle,andisfreelyavailableforuse.
MySQLworksonmanysystemplatforms,includingAIX,BSDi,FreeBSD,HP-UX,eComStation,i5/OS,IRIX,Linux,OSX,MicrosoftWindows,NetBSD,NovellNetWare,OpenBSD,OpenSolaris,OS/2Warp,QNX,OracleSolaris,Symbian,SunOS,SCOOpenServer,SCOUnixWare,SanosandTru64.AportofMySQLtoOpenVMSalsoexists.
3Part:1
CreatingDatabases,Tables
____________________________________________________________InthisPart
CreateDatabaseCreateTableSetPrimaryKeyinTableCreationSetForeignKeyinTableCreationSetdefaultvalueincreatetable
;(Semicolon) isanecessarysymbolatendofallMySQLStructure.
CreateDatabase:CreateadatabaseinMySQLThe CREATEDATABASE statementisusedtocreateadatabase.
Syntax:-Createdatabase<databasename>;
Example:-Createdatabasemywebsite;
Createtable:
4
CreatetablesinMySQL
The CREATETABLE statementisusedtocreateatableinadatabase.
Tablesareorganizedintorowsandcolumns;andeachtablemusthaveaname.
1. Createtablequery
Syntax:-Createtable<tablename>(<columnname><datatype>(size),<columnname><datatype>(size),………)
Thecolumnnameparametersspecifythenamesofthecolumnsofthetable.
Thedatatypeparameterspecifieswhattypeofdatathecolumncanhold(e.g.varchar,integer,decimal,date,etc.).
Thesizeparameterspecifiesthemaximumlengthofthecolumnofthetable.
Example:-Createtableworldfreeapps(Srinteger(5),Appstorechar(20),Songchar(20),Gamechar(30));
2. Setnotnullvalueondefaultpositionintablecreate
The NOTNULL constraintenforcesacolumnto NOT accept NULL values.
The NOTNULL constraintenforcesafieldtoalwayscontainavalue.Thismeansthatyoucannotinsertanewrecord,orupdatearecordwithoutaddingavaluetothisfield.
5
Example:-Createtableworldfreeapps(Srinteger(5)notnull,Appstorechar(20)notnull,Songchar(20));
3. SetdefaultvalueinCreatetable
The DEFAULT constraintisusedtoinsertadefaultvalueintoacolumn.
Thedefaultvaluewillbeaddedtoallnewrecords,ifnoothervalueisspecified.
Example:-Createtableworldfreeapps(Srinteger(5)default,Appstorechar(20),Songchar(20));
4. Checkdefaultconditionintablecreate
The CHECK constraintisusedtolimitthevaluerangethatcanbeplacedinacolumn.
Ifyoudefinea CHECK constraintonasinglecolumnitallowsonlycertainvaluesforthiscolumn.
Ifyoudefinea CHECK constraintonatableitcanlimitthevaluesincertaincolumnsbasedonvaluesinothercolumnsintherow.
Example:-Createtableworldfreeapps(Srinteger(5)check(Sr>2),Appstorechar(20),Songchar(20));
5. SetPrimaryKeyintablecreation
The PRIMARYKEY constraintuniquelyidentifieseachrecordinadatabasetable.
6
Primarykeysmustcontain UNIQUE values.
Aprimarykeycolumncannotcontain NULL values.
Mosttablesshouldhaveaprimarykey,andeachtablecanhaveonlyONEprimarykey.
Example:-Createtableworldfreeapps(Srinteger(5)primarykey,Appstorechar(20),Songchar(20));
Or
Example:-Createtableworldfreeapps(Srinteger(5),Appstorechar(20),Songchar(20),primarykey(Sr));
6. SetForeignKeyintablecreation
AFOREIGNKEY inonetablepointstoaPRIMARYKEYinanothertable.
Example:-Createtableworldfreeapps(Srinteger(5),Appstorechar(20),Songchar(20),Gamechar(20),foreignkey(Sr)referencesworld(Sr));
7Part:2
AccessingDatabases_______________________________________________________InthisPart
UseDatabase
UseDatabase:With USEDATABASE Statementyoucanaccessanyofdatabasesin MySQL
Syntax:-Use<databasename>;
Example:-usemywebsite;
8Part:3
InsertingDataintoTable_______________________________________________________InthisPart
InsertDataintoTableInsertNullValues
InsertingDataintoTable:The INSERTINTO statementisusedtoinsertnewrecordsinatable.
1. InsertDataintoTable
Syntax:-Insertinto<tablename>values(<value>,<value>,……);
Example:-insertintoworldfreeappsvalues(1,’Android’,’Music’);
OrSyntax:-Insertinto<tablename>(<column1>,<column2>,….)values(<value1>,<value2>,…..);
Example:-insertintoworldfreeapps(Sr,Appstore,Song)values(1,’Android’,’Music’);
9
2. InsertNullValues
Syntax:-Insertinto<tablename>(<column1>,<column2>,….)values(<value1>,<value2>,…..);
Example:-insertintoworldfreeapps(Sr,Appstore,Song)values(1,’Android’,NULL);
10Part:4
AlteringTable____________________________________________________InthisPart
AddColumn,PrimaryKeyDeleteColumn,PrimaryKey,Row,Table,DatabaseModifyTable
The ALTERTABLE statementisusedtoadd,delete,ormodifycolumnsinanexistingtable.
AddColumn,PrimaryKey:
1. AddnewColumn
Syntax:-altertable<tablename>add(<columnname><datatype>(<size>));
Example:-altertableworldfreeappsadd(Aboutchar(30));
2. AddPrimaryKey
11
Syntax:-altertable<tablename>addprimarykey(<columnname>);
Example:-altertableworldfreeappsaddprimarykey(Sr);
DeleteColumn,PrimaryKey,Row,Table,
Database:
1. DeleteColumn
Syntax:-altertable<tablename>drop<columnname>;
Example:-altertableworldfreeappsdropAbout;
2. DeletePrimaryKey
Syntax:-altertable<tablename>dropprimarykey;
Example:-altertableworldfreeappsdropprimarykey;
3. DeleteRow
Syntax:-deletefrom<tablename>where<columnnameequalsvalue>;
Example:-deletefromworldfreeappswhereSr=2;
4. DeleteTable
The DROPTABLE statementisusedtodeleteatable.
12
Syntax:-droptable<tablename>;
Example:-droptableworldfreeapps;
5. DeleteDatabaseThe DROPDATABASE statementisusedtodeleteadatabase.
Syntax:-dropdatabase<databasename>;
Example:-dropdatabasemywebsite;
ModifyTable:
1. ChangeColumnName,DataType
Syntax:-altertable<tablename>change<columnname><changedcolumnname><datatype(<size>)>;
Example:-altertableworldfreeappschangeSongMusicchar(30);
2. UpdateTableData
Syntax:-update<tablename>set<columnnameequalchangeddata>;
Example:-updateworldfreeappssetAppStore=“IOS”whereSr=2;
13
3. ShowTableindatabase
Syntax:-showtables;
Example:-showtables;
4. StructureofTableSyntax:-desc<tablename>;
Example:-descworldfreeapps;
14Part:5
SelectQueries_____________________________________________InthisPart
FormatofSelectQuerySelectQueries
SELECTQUERY isusedfordisplayingyourtableinthatmannerinwhichyouwant.
FormatofSelectQuery:
SelectQueryFormatSyntax:-Select<whattoselect>from<whichtable>where<conditiontosatisfy>;
SelectQueries:1. Selectingalldatafromatable
Syntax:-select*from<tablename>;
Example:-select*fromworldfreeapps;
2. SelectalldatawhereAppstore=Android
15
Syntax:-select*from<tablename>where<conditiontosatisfy>;
Example:-select*fromworldfreeappswhereAppstore=“Android”;
3. SelectallDatawhereSr>=2
Syntax:-select*from<tablename>where<conditiontosatisfy>;
Example:-select*fromworldfreeappswhereSr>=2;
4. SelectallDatausing“and”conditionwherebothconditionarecompulsory
Syntax:-select*from<tablename>where<conditiontosatisfy>;
Example:-select*fromworldfreeappswhereSr=2andAppstore=’Windows’;
5. Selectalldatausing“or”conditionwhereanyconditionarematchfrombothcondition
Syntax:-select*from<tablename>where<conditiontosatisfy>;
Example:-select*fromworldfreeappswhereSr=2orAppstore=’Windows’;
16
6. SelectingParticularColumn
Syntax:-select<whichcolumntobedisplayed>from<tablename>;
Example:-selectSr,Appstorefromworldfreeapps;
7. RemoveDuplicateDataforShowingfromTable
Syntax:-selectdistinct(<columnname>)from<tablename>;
Example:-selectdistinct(Appstore)fromworldfreeapps;
8. SelectallDatafromParticularTable
Syntax:-selectall<columnname>from<tablename>;
Example:-selectallAppstorefromworldfreeapps;
9. UsingColumnAliases
Syntax:-select<columnname>as<“ColumnAliasesName”>from<tablename>;
Example:-selectSr,Appstoreas“TwoColumn”fromworldfreeapps;
10. ConditionBasedonaRange
17
Syntax:-select<columnwhichtobedisplay>from<tablename>where<conditiontosatisfy>;
Example:-selectSr,AppstorefromworldfreeappswhereSrbetween2and5;
11. ConditionBasedonaList
Syntax:-select<columnwhichtobedisplay>from<tablename>where<conditiontosatisfy>;
Example:-select*fromworldfreeappswhereAppstorein(‘appstore’,’appstore2’,’appstore3’);
12. ConditionBasedonPatternMatches
NamelikeStartingfroma
Syntax:-select*from<tablename>where<columnname>like‘<letter>%’;
Example:-select*fromworldfreeappswhereAppstorelike‘a%’;
NamelikeEndingfromt
Syntax:-select*from<tablename>where<columnname>like‘%<letter>’;
Example:-select*fromworldfreeappswhereAppstorelike‘%t’;
18
WordAnywhereinAppstore
Syntax:-select*from<tablename>where<columnname>like‘%a%’;
Example:-select*fromworldfreeappswhereAppstorelike‘%a%’;
13. SearchingforNull
Syntax:-select*from<tablename>where<columnname>isNull
Example:-select*fromworldfreeappswhereSongisNull;
14. ShortingRecordsOrderbyValue
AscendingOrder
Syntax:-select*from<tablename>orderby<columnname>;
Example:-select*fromworldfreeappsorderbyAppstore;
DescendingOrder
Syntax:-select*from<tablename>orderby<columnname>desc;
Example:-select*fromworldfreeappsorderbyAppstoredesc;
19
15. PerformingSimpleCalculation
ArithmeticOperation
Select1+5;
FindCurrentSystemDate
Selectcurdate();
20Part:6
MySQLFunctions____________________________________________________________InthisPart
StringfunctionsNumericfunctions
Stringfunctions:
1.ReturntheCharacterfromeachintegerpassed
CHAR() interpretseachargumentNasanintegerandreturnsastringconsistingofthecharactersgivenbythecodevaluesofthoseintegers. NULL valuesareskipped.
Syntax:-selectchar(<numeric1>,<numeric2>,<numeric3>,…);
Example:-selectchar(65,66,67,68);
2.ReturnConcatenatedString
Returnsthestringthatresultsfromconcatenatingthearguments.
Syntax:-selectconcat(<columnname1>,<columnname2>,…)as“<asnameyouwanttodisplay>”from<tablename>;
21
Example:-selectconcat(Sr,Appstore)as“SrandAppstore”fromworldfreeapps;
3.ChangedatainLowerCaseandUpperCase
LowerCase
Syntax:-selectlower(<columnname>)from<tablename>;
Example:-selectlower(Appstore)fromworldfreeapps;
Or
Syntax:-selectlcase(<columnname>)from<tablename>;
Example:-selectlcase(Appstore)fromworldfreeapps;
UpperCase
Syntax:-selectupper(<columnname>)from<tablename>;
Example:-selectupper(Appstore)fromworldfreeapps;
Or
Syntax:-selectucase(<columnname>)from<tablename>;
Example:-selectucase(Appstore)fromworldfreeapps;
4.SubstringdatainColumn
22
Syntax:-selectsubstr(<Columnname>,<lettertobedisplayednumbering>)from<tablename>;
Example:-selectsubstr(Appstore,1,2)fromworldfreeapps;
Or
Syntax:-selectsubstring(<Columnname>,<lettertobedisplayednumbering>)from<tablename>;
Example:-selectsubstring(Appstore,1,2)fromworldfreeapps;
Or
Syntax:-selectmid(<Columnname>,<lettertobedisplayednumbering>)from<tablename>;
Example:-selectmid(Appstore,1,2)fromworldfreeapps;
5.RemovingLeadingSpaces
Syntax:-slectltrim(<columnname>)from<tablename>;
Example:-selectltrim(Appstore)fromworldfreeapps;
6.RemovingTrailingSpaces
Syntax:-slectrtrim(<columnname>)from<tablename>;
Example:-selectrtrim(Appstore)fromworldfreeapps;
7.RemovingLeadingandTrailingSpaces
23
Syntax:-slecttrim(<columnname>)from<tablename>;
Example:-selecttrim(Appstore)fromworldfreeapps;
8.ShowtheindexoftheString
Syntax:-selectinstr(<columnname>,<”letter”>)from<tablename>;
Example:-selectinstr(Appstore,”a”)fromworldfreeapps;
9.ShowthelengthoftheString
Syntax:-selectlength(<columnname>)as“<thenameyouwanttodisplay>”from<tablename>;
Example:-selectlength(Appstore)as“OperatingSystems”fromworldfreeapps;
10.ShowleftmostnumberofCharacter
Syntax:-selectleft(<columnname>,<size>)as<“thenameyouwanttodisplay”>from<tablename>;
Example:-selectleft(Appstore,3)as“leftmost”fromworldfreeapps;
11.ShowrightmostnumberofCharacter
Syntax:-selectright(<columnname>,<size>)as<“thenameyouwanttodisplay”>from<tablename>;
24
Example:-selectright(Appstore,3)as“rightmost”fromworldfreeapps;
Numericfunctions:
1. Showthereminderofoneexpressiondividedbyanotherexpression
Syntax:-selectmod(<expression1>,<expression2>);
Example:-selectmod(11,4);
2. ShowthePowerofanyValue
Syntax:-selectpower(value1,value2);
Example:-selectpower(12,2);
3. Showthenumericexpressionroundedtoaninteger
Syntax:-selectround(<numeric>);
Example:-selectround(35.323,1);
4. Showthenumericexpressiontruncatedtoaninteger
Syntax:-selecttruncate(<numeric>)as“<thenameyouwanttodisplay>”;
Example:-selecttruncate(15.79,1)as“truncate”;
5. Showthesignofnumericvalues
25
Syntax:-selectsign(<thatyouwanttoselect>)as“<thenameyouwanttodisplay>”;
Example:-selectsign(-1)as“sign”;
6. Showthesquarerootofanynumber
Syntax:-selectsqrt(<numeric>)as“<thenameyouwanttodisplay>”;
Example:-selectsqrt(36)as“sqrt”;
26Part:7
MySQLJoin____________________________________________________
InthisPart
MySQLJoinDifferentMySQLJoin
MySQLJoin:1. AboutMySQLJoin
AMySQLJoinclauseisusedtocombinerowsfromtwoormoretables,basedonacommonfieldbetweenthem.
ThemostcommontypeofJoinis:MySQLINNERJOIN(simplejoin).AMySQLINNERJOINreturnallrowsfrommultipletableswherethejoinconditionismet.
2. MySQLJoinSyntax
Syntax:-select<tablename1.itscolumnname>,<tablename2.itscolumnname>from<tablename1>innerjoin<tablename2>on<tablename1.samecolumnname>=<tablename2.samecolumnname>;
3. MySQLJoinExample
Example:-
27
Let’slookataselectionfromthe“Persons”table:
SrPersonIDOrderDate
1030821996-09-18
10309371996-09-19
10310771996-09-20
Then,havealookataselectionfromthe“Customer”table:
PersonIDNameContactNameCountry
1AlfredsFutterkisteMariaGermany
2AnaTrujilloAnaMexico
3AntonioMorenoAntonioMexico
Then,ifwerunthefollowingMySQLstatement
SelectPersons.Sr,Customers.Name,Persons.OrderDateFromPersonsInnerJoinCustomersONPersons.PersonID=Customers.PersonID;
Itwillproducesomethinglikethis:
SrNameOrderDate
10308AnaTrujilli1996-09-18
DifferentMySQLJoin:
28
1. DifferentMySQLJoins
INNERJOIN:ReturnsallrowswhenthereisatleastonematchinBOTHtablesLEFTJOIN:Returnallrowsfromthelefttable,andthematchedrowsfromtherighttableRIGHTJOIN:Returnallrowsfromtherighttable,andthematchedrowsfromthelefttableFULLJOIN:ReturnallrowswhenthereisamatchinONEofthetables
29Part:8
MySQLCreateIndex____________________________________________________________InthisPart
CreateIndexCreateUniqueIndexDeleteIndex
TheCREATEINDEXstatementisusedtocreateindexesintables.Indexesallowthedatabaseapplicationtofinddatafast;withoutreadingthewholetable.
CreateIndex:1. MySQLCreateIndex
Syntax:-CREATEINDEX<indexname>ON<tablename>(<columnname>);
Example:-CREATEINDEXPIndexONPersons(Name);
CreateUniqueIndex:
1. MySQLCreateUniqueIndex
30
Syntax:-CREATEUNIQUEINDEX<indexname>ON<tablename>(<columnname>);
Example:-CREATEUNIQUEPIndexONPersons(Name);
DeleteIndex:
1. DeleteCreatedIndex
Syntax:-altertable<tablename>dropindex<indexname>;
Example:-altertableworldfreeappsdropindexAndroid;
31Part:9
MySQLAutoIncrementafield____________________________________________________
InthisPart
AddAutoIncrementinafieldintable
AutoIncrementallowsauniquenumbertobegeneratedwhenanewrecordisinsertedintoatable.
AddAutoIncrementinafieldintable:
1. MySQLAutoIncrement
Syntax:-CreateTable<tablename>(<columnname1><datatype(<size>)>Auto_Increment,<columnname2><datatype(<size>)>,….);
Example:-CreateTableworldfreeapps(SrintNotNullAuto_Increment,Namevarchar(255),PrimaryKey(Sr));
TolettheAUTO_INCREMENTsequencestartwithanothervalue,usethefollowingMySQLstatement:
Syntax:-altertable<tablename>Auto_Increment=<size>;
Example:-altertableworldfreeappsAuto_Increment=100;
32Part:10
MySQLViews____________________________________________________InthisPart
CreateViewReplaceViewDropView
CreateView:
1. MySQLCreateView
Syntax:-Createview<viewname>asselect<columnname>from<tablename>;
Example:-CreateviewvasselectSr,AppstorefromPersons;
ReplaceView:1. MySQLReplaceView
Syntax:-CreateorReplaceview<viewname>asselect<columnname>from<tablename>;
Example:-CreateviewvasselectSr,Appstore,AboutfromPersons;
DropView:
33
1. MySQLDropView
Syntax:-Dropview<viewname>;
Example:-Dropviewv;
34Part:11
MySQLReference____________________________________________________
MySQLReference:
SQLStatement Syntax
AND/OR SELECTcolumn_name(s)FROMtable_nameWHEREconditionAND|ORcondition
ALTERTABLE ALTERTABLEtable_nameADDcolumn_namedatatype
or
ALTERTABLEtable_nameDROPCOLUMNcolumn_name
AS(alias) SELECTcolumn_nameAScolumn_aliasFROMtable_name
or
SELECTcolumn_nameFROMtable_nameAStable_alias
BETWEEN SELECTcolumn_name(s)FROMtable_nameWHEREcolumn_nameBETWEENvalue1ANDvalue2
CREATEDATABASE CREATEDATABASEdatabase_name
CREATETABLE CREATETABLEtable_name(column_name1data_type,column_name2data_type,column_name3data_type,…)
CREATEINDEX CREATEINDEXindex_nameONtable_name(column_name)
or
CREATEUNIQUEINDEXindex_nameONtable_name(column_name)
CREATEVIEW CREATEVIEWview_nameASSELECTcolumn_name(s)FROMtable_nameWHEREcondition
DELETE DELETEFROMtable_nameWHEREsome_column=some_value
or
DELETEFROMtable_name(Note:Deletestheentiretable!!)
DELETE*FROMtable_name(Note:Deletestheentiretable!!)
DROPDATABASE DROPDATABASEdatabase_name
DROPINDEX DROPINDEXtable_name.index_name(SQLServer)DROPINDEXindex_nameONtable_name(MSAccess)DROPINDEXindex_name(DB2/Oracle)ALTERTABLEtable_nameDROPINDEXindex_name(MySQL)
DROPTABLE DROPTABLEtable_name
EXISTS IFEXISTS(SELECT*FROMtable_nameWHEREid=?)BEGIN—dowhatneedstobedoneifexistsENDELSEBEGIN—dowhatneedstobedoneifnotEND
GROUPBY SELECTcolumn_name,aggregate_function(column_name)FROMtable_nameWHEREcolumn_nameoperatorvalueGROUPBYcolumn_name
HAVING SELECTcolumn_name,aggregate_function(column_name)FROMtable_nameWHEREcolumn_nameoperatorvalueGROUPBYcolumn_nameHAVINGaggregate_function(column_name)operatorvalue
IN SELECTcolumn_name(s)FROMtable_nameWHEREcolumn_nameIN(value1,value2,..)
INSERTINTO INSERTINTOtable_nameVALUES(value1,value2,value3,….)
or
INSERTINTOtable_name(column1,column2,column3,…)VALUES(value1,value2,value3,….)
INNERJOIN SELECTcolumn_name(s)FROMtable_name1INNERJOINtable_name2ONtable_name1.column_name=table_name2.column_name
LEFTJOIN SELECTcolumn_name(s)FROMtable_name1LEFTJOINtable_name2ONtable_name1.column_name=table_name2.column_name
RIGHTJOIN SELECTcolumn_name(s)FROMtable_name1RIGHTJOINtable_name2ONtable_name1.column_name=table_name2.column_name
FULLJOIN SELECTcolumn_name(s)FROMtable_name1FULLJOINtable_name2ONtable_name1.column_name=table_name2.column_name
LIKE SELECTcolumn_name(s)FROMtable_nameWHEREcolumn_nameLIKEpattern
ORDERBY SELECTcolumn_name(s)FROMtable_nameORDERBYcolumn_name[ASC|DESC]
SELECT SELECTcolumn_name(s)FROMtable_name
SELECT* SELECT*FROMtable_name
SELECTDISTINCT SELECTDISTINCTcolumn_name(s)FROMtable_name
SELECTINTO SELECT*INTOnew_table_name[INexternaldatabase]FROMold_table_name
or
SELECTcolumn_name(s)INTOnew_table_name[INexternaldatabase]FROMold_table_name
SELECTTOP SELECTTOPnumber|percentcolumn_name(s)FROMtable_name
TRUNCATETABLE TRUNCATETABLEtable_name
UNION SELECTcolumn_name(s)FROMtable_name1UNIONSELECTcolumn_name(s)FROMtable_name2
UNIONALL SELECTcolumn_name(s)FROMtable_name1UNIONALLSELECTcolumn_name(s)FROMtable_name2
UPDATE UPDATEtable_nameSETcolumn1=value,column2=value,…
WHEREsome_column=some_value
WHERE SELECTcolumn_name(s)FROMtable_nameWHEREcolumn_nameoperatorvalue
38Part:12
AboutMySQL____________________________________________________________
MySQLis(asofJuly2013)theworld’ssecondmostwidelyusedrelationaldatabasemanagementsystem(RDBMS)andmostwidelyusedopen-sourceRDBMS.
TheMySQLdevelopmentprojecthasmadeitssourcecodeavailableunderthetermsoftheGNUGeneralPublicLicense,aswellasunderavarietyofproprietaryagreements.
MySQLisapopularchoiceofdatabaseforuseinwebapplications,andisacentralcomponentofthewidelyusedLAMPopensourcewebapplicationsoftwarestack(andother‘AMP’stacks).
MySQLiswritteninCandC++.ItsSQLparseriswritteninyacc,butitusesahome-brewedlexicalanalyzer.
39
MySQLworksonmanysystemplatforms,includingAIX,BSDi,FreeBSD,HP-UX,eComStation,i5/OS,IRIX,Linux,OSX,MicrosoftWindows,NetBSD,NovellNetWare,OpenBSD,OpenSolaris,OS/2Warp,QNX,OracleSolaris,Symbian,SunOS,SCOOpenServer,SCOUnixWare,SanosandTru64.AportofMySQLtoOpenVMSalsoexists.
MySQLcanbebuiltandinstalledmanuallyfromsourcecode,butthiscanbetedioussoitismorecommonlyinstalledfromabinarypackageunlessspecialcustomizationsarerequired.
Backupsoftwarearecomputerprogramsusedtoperformbackup;theycreatesupplementaryexactcopiesoffiles,databasesorentirecomputers.
LikeotherSQLdatabases,MySQLdoesnotcurrentlycomplywiththefullSQLstandardforsomeoftheimplementedfunctionality,includingforeignkeyreferenceswhenusingsomestorageenginesotherthanthedefaultofInnoDB,andcheckconstraints.
UpuntilMySQL5.7,triggersarelimitedtooneperaction/timing,meaningthatatmostonetriggercanbedefinedtobeexecutedafteranINSERToperation,andonebeforeINSERTonthesametable.Notriggerscanbedefinedonviews.
40
MySQLdatabase’sinbuiltfunctionslikeUNIX_TIMESTAMP()willreturn0after03:14:07UTCon19January2038.
OnallplatformsexceptWindows,MySQLshipswithnoGUItoolstoadministerMySQLdatabasesormanagedatacontainedwithinthedatabases.Usersmayusetheincludedcommandlinetools,orinstallMySQLWorkbenchviaaseparatedownload.ManythirdpartyGUItoolsarealsoavailable.
Adminer(formerlyknownasphpMinAdmin)isafreeMySQLfrontendformanagingcontentinMySQLdatabases(sinceversion2,italsoworksonPostgreSQL,MSSQL,SQLiteandOracleSQLdatabases).
MySQLWorkbenchistheofficialintegratedenvironmentforMySQL.ItwasdevelopedbyMySQLAB,andenablesuserstographicallyadministerMySQLdatabasesandvisuallydesigndatabasestructures.
MySQLforBeginnersMySQLforBeginneriswrittenbyGaneshBagaria.Thisishisfirstbook.Foranymistakessorry.InthisbookyougetalltheMySQLStatements,Queries,AboutMySQL,UsesofMySQL,allQueries,MySQLTools,MySQluse,aboutdatabases,MySQLwebtool,etc.
Andotherthings.PublishedbyGaneshBagariaPrice:1.99$