Tải bản đầy đủ - 0 (trang)
Hack 49. Create Access Tables with SQL Server Scripts

Hack 49. Create Access Tables with SQL Server Scripts

Tải bản đầy đủ - 0trang

37.Afteryouselectadestinationforthescript,afileiscreated.

AtextfileiswrittenwithSQLServerspecificSQLstatements.

Figure5-38showsthegeneratedscriptopenedinNotepad.



Figure5-36.ExploringEnterpriseManager



Figure5-37.PreparingtogenerateaSQLscript



Asis,thisscriptwon'tworkifit'sruninsideanAccessquery.

Thepertinentpartisinthemiddle,startingwiththeCreateTable

statement.CreateTableisrecognizableSQLinAccess.Evenso,

thefieldtypesaren'tcorrectinAccess,sowestillhavetoclean

thisup.KnowingwhattodorequiresalittleSQLknowledge,

butifyouhaven'tlearnedanyyet,it'snotabadthingtogetto

know.



Figure5-38.Thegeneratedscript



PlentyofbooksareavailableonthesubjectofSQL.Seetheendofthis

hackforashortlist.



Onceyou'vecleaneduptheSQL,andit'sreadyforAccess,you

needtocallupaDataDefinitionquery.Figure5-39showswhere

toaccessthisspecialtypeofqueryinAccess.



Figure5-39.CreatingaDataDefinitionquery



Onceyouselectthequerytype,youareleftinapaneinwhich

SQLisentered.Figure5-40showsthepanewiththeeditedSQL

script.NowitisreadytoruninAccess.

Sureenough,whenthisqueryruns,itcreatesanewtblClients

table.So,essentially,notonlyisitpossibletorecreateaSQL

schemainAccess,butyoualsocaneditaSQLServergenerated

scripttogetthejobdone.



Figure5-40.ASQLscript,readytoruninAccess



5.11.2.SeeAlso

SQLPocketGuide(O'Reilly)

SQLinaNutshell(O'Reilly)



Hack50.UseWildcardsinQueries



TheLikeoperatorcomesinhandywhenyoudon'tquite

rememberhowtospelladataitem.

Whenyoucanrememberonlyapartialamountofinformation,

agreatwaytosearchthroughyourdatabaserecordsistouse

theSQLLikeoperator.CombiningLikewithwildcardsmakesfor

somepowerfulqueries.

Forexample,imagineyouhaveadatabasetablefilledwith

customerrecords.Youneedtolookupsomeonewhoselast

namestartswithDe,andthat'sallyoucanrecallabouther

name.

Figure5-41showsaquerythatusestheasterisk(*)wildcardto

findallcustomerswhoselastnamestartswithDe.Theasterisk

isaplaceholderforanynumberofcharacters.Therefore,

runningthisqueryreturnsallcustomerswithDeasthefirsttwo

charactersintheirlastname.

Let'ssayinsteadthatyourememberthelastnamestartswith

Dandisfourcharacterslong.Inthiscase,thequestionmark

(?)wildcardcomesinhandy.Youusethequestionmarkasa

placeholdertorepresentasinglecharacter.Figure5-42shows

threequestionmarksbeingusedtomakeupforthreespaces

aftertheletterD.

Figure5-43showstheresultofrunningthequery.All

customerswithfour-characterlastnamesthatstartwithDare

returned.

Usingwildcardsletsyoureallygettoyourdataincreative

ways.Youmightrecallthefirstandlastletterofaname,or



evenjustthatanameisfourcharacterslong,butyoudon't

rememberanyoftheactualcharacters!Insuchascase,usinga

criterionofLike"????"returnsallcustomerswithlastnamesthat

arefourcharacterslong,asshowninFigure5-44.



Figure5-41.Findingcustomerswithanasterisk

wildcard



Figure5-42.Findingcustomersusingquestion

marks



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Hack 49. Create Access Tables with SQL Server Scripts

Tải bản đầy đủ ngay(0 tr)

×