Sunteți pe pagina 1din 3

TRANSLATE

Searchw3schools.com Search

H O M E H T M L C S S X M L J A V A S C R I P T A S P P H P S Q L MORE...

REFERENCES | EXAMPLES | FORUM | ABOUT

SQLBasic
SQLHOME SQLIntro SQLSyntax SQLSelect SQLDistinct SQLWhere SQLAnd&Or SQLOrderBy SQLInsert SQLUpdate SQLDelete

SQLSyntax
Previous NextChapter

DatabaseTables
Adatabasemostoftencontainsoneormoretables.Eachtableisidentifiedbyaname(e.g. "Customers"or"Orders").Tablescontainrecords(rows)withdata. Belowisanexampleofatablecalled"Persons": P_Id 1 2 3 LastName Hansen Svendson Pettersen FirstName Ola Tove Kari Address Timoteivn10 Borgvn23 Storgt20 City Sandnes Sandnes Stavanger

SQLDemo
SQLTryIt

SQLAdvanced
SQLTop SQLLike SQLWildcards SQLIn SQLBetween SQLAlias SQLJoins SQLInnerJoin SQLLeftJoin SQLRightJoin SQLFullJoin SQLUnion SQLSelectInto SQLCreateDB SQLCreateTable SQLConstraints SQLNotNull SQLUnique SQLPrimaryKey SQLForeignKey SQLCheck SQLDefault SQLCreateIndex SQLDrop SQLAlter SQLIncrement SQLViews SQLDates SQLNulls SQLisnull() SQLDataTypes

Thetableabovecontainsthreerecords(oneforeachperson)andfivecolumns(P_Id,LastName, FirstName,Address,andCity).

SQLStatements
MostoftheactionsyouneedtoperformonadatabasearedonewithSQLstatements. ThefollowingSQLstatementwillselectalltherecordsinthe"Persons"table:

SELECT*FROMPersons

InthistutorialwewillteachyouallaboutthedifferentSQLstatements.

KeepinMindThat...
l

SQLisnotcasesensitive

SQLFunctions
SQLFunctions SQLavg() SQLcount() SQLfirst() SQLlast() SQLmax() SQLmin() SQLsum() SQLGroupBy SQLHaving SQLucase() SQLlcase() SQLmid() SQLlen() SQLround() SQLnow() SQLformat() SQLQuickRef SQLHosting SQLSummary

SemicolonafterSQLStatements?
SomedatabasesystemsrequireasemicolonattheendofeachSQLstatement. SemicolonisthestandardwaytoseparateeachSQLstatementindatabasesystemsthatallow morethanoneSQLstatementtobeexecutedinthesamecalltotheserver. WeareusingMSAccessandSQLServer2000andwedonothavetoputasemicolonaftereach SQLstatement,butsomedatabaseprogramsforceyoutouseit.

SQLDMLandDDL
SQLcanbedividedintotwoparts:TheDataManipulationLanguage(DML)andtheDataDefinition Language(DDL). ThequeryandupdatecommandsformtheDMLpartofSQL:
l l l l

SQLQuiz
SQLQuiz

SELECT extractsdatafromadatabase UPDATE updatesdatainadatabase DELETE deletesdatafromadatabase INSERTINTO insertsnewdataintoadatabase

TheDDLpartofSQLpermitsdatabasetablestobecreatedordeleted.Italsodefineindexes(keys), specifylinksbetweentables,andimposeconstraintsbetweentables. ThemostimportantDDL statementsinSQLare:


l l l l

CREATEDATABASE createsanewdatabase ALTERDATABASE modifiesadatabase CREATETABLE createsanewtable ALTERTABLE modifiesatable

INSERTINTO insertsnewdataintoadatabase

TheDDLpartofSQLpermitsdatabasetablestobecreatedordeleted.Italsodefineindexes(keys), specifylinksbetweentables,andimposeconstraintsbetweentables. ThemostimportantDDL statementsinSQLare:


l l l l l l l

CREATEDATABASE createsanewdatabase ALTERDATABASE modifiesadatabase CREATETABLE createsanewtable ALTERTABLE modifiesatable DROPTABLE deletesatable CREATEINDEX createsanindex(searchkey) DROPINDEX deletesanindex

Previous
WEBHOSTING BestWebHosting PHPMySQLHosting Top10WebHosting UKResellerHosting CloudHosting TopWebHosting $7.95/moSEOHosting WEBBUILDING XMLEditorFreeTrial! FREEWebsiteBUILDER FreeWebsiteTemplates FreeWordPressThemes W3SCHOOLSEXAMS GetCertifiedin: HTML,CSS,JavaScript, XML,PHP,andASP W3SCHOOLSBOOKS NewBooks: HTML,CSS JavaScript,andAjax STATISTICS BrowserStatistics BrowserOS BrowserDisplay SHARETHISPAGE Sharewith

NextChapter

R E P O R T E R R O R | HOME | TOP | PRINT | FORUM | ABOUT

W3Schoolsisoptimizedforlearning,testing,andtraining.Examplesmightbesimplifiedtoimprovereadingandbasicunderstanding.

R E P O R T E R R O R | HOME | TOP | PRINT | FORUM | ABOUT

W3Schoolsisoptimizedforlearning,testing,andtraining.Examplesmightbesimplifiedtoimprovereadingandbasicunderstanding. Tutorials,references,andexamplesareconstantlyreviewedtoavoiderrors,butwecannotwarrantfullcorrectnessofallcontent. Whileusingthissite,youagreetohavereadandacceptedour termsofuse andprivacypolicy . Copyright1999 2011byRefsnesData.AllRightsReserved.

S-ar putea să vă placă și