CREATETABLE–SQLCommand
来源:互联网 发布:湖北襄阳seo 编辑:程序博客网 时间:2024/05/04 06:40
Createsatablehavingthespecifiedfields.
- TableName1
- Specifiesthenameofthetabletocreate.TheTABLEandDBFoptionsareidentical.
- NAMELongTableName
- Specifiesalongnameforthetable.Alongtablenamecanbespecifiedonlywhenadatabaseisopenbecauselongtablenamesarestoredindatabases.
Longnamescancontainupto128charactersandcanbeusedinplaceofshortfilenamesinthedatabase.
- FREE
- Specifiesthatthetablewillnotbeaddedtoanopendatabase.FREEisn'trequiredifadatabaseisn'topen.
- (FieldName1FieldType[(nFieldWidth[,nPrecision])]
- Specifiesthefieldname,fieldtype,fieldwidth,andfieldprecision(numberofdecimalplaces),respectively.
Asingletablecancontainupto255fields.Ifoneormorefieldsallownullvalues,thelimitisreducedbyoneto254fields.
FieldTypeisasingleletterindicatingthefield'sdatatype.SomefielddatatypesrequirethatyouspecifynFieldWidthornPrecision,orboth.
ThefollowingtableliststhevaluesforFieldTypeandwhethernFieldWidthandnPrecisionarerequired.
FieldType nFieldWidth nPrecision DescriptionCharacterfieldofwidthnNumericfieldofwidthnwithddecimalplacesFloatingnumericfieldofwidthnwithddecimalplaces nFieldWidthandnPrecisionareignoredforD,T,I,Y,L,M,G,andPtypes.nPrecisiondefaultstozero(nodecimalplaces)ifnPrecisionisn'tincludedfortheNorFtypes.nPrecisiondefaultstothenumberofdecimalplacesspecifiedbytheSETDECIMALsettingifnPrecisionisn'tincludedfortheBtype.
- NULL
- Allowsnullvaluesinthefield.Ifoneormorefieldscancontainnullvalues,themaximumnumberoffieldsthetablecancontainisreducedbyone,from255to254.
- NOTNULL
- Preventsnullvaluesinthefield.
IfyouomitNULLandNOTNULL,thecurrentsettingofSETNULLdeterminesifnullvaluesareallowedinthefield.However,ifyouomitNULLandNOTNULLandincludethePRIMARYKEYorUNIQUEclause,thecurrentsettingofSETNULLisignoredandthefielddefaultstoNOTNULL.
- CHECKlExpression1
- Specifiesavalidationruleforthefield.lExpression1canbeauser-definedfunction.Notethatwhenablankrecordisappended,thevalidationruleischecked.Anerrorisgeneratedifthevalidationruledoesn'tallowforablankfieldvalueinanappendedrecord.
- ERRORcMessageText1
- SpecifiestheerrormessageVisualdisplayswhenthevalidationrulespecifiedwithCHECKgeneratesanerror.ThemessageisdisplayedonlywhendataischangedwithinaBrowsewindoworEditwindow.
- DEFAULTeExpression1
- Specifiesadefaultvalueforthefield.ThedatatypeofeExpression1mustbethesameasthefield'sdatatype.
- PRIMARYKEY
- Createsaprimaryindexforthefield.Theprimaryindextaghasthesamenameasthefield.
- UNIQUE
- Createsacandidateindexforthefield.Thecandidateindextaghasthesamenameasthefield.Formoreinformationaboutcandidateindexes,seeSettingaPrimaryorCandidateIndex.
Note Candidateindexes(createdbyincludingtheUNIQUEoptioninCREATETABLEorALTERTABLE–SQL)arenotthesameasindexescreatedwiththeUNIQUEoptionintheINDEXcommand.AnindexcreatedwiththeUNIQUEoptionintheINDEXcommandallowsduplicateindexkeys;candidateindexesdonotallowduplicateindexkeys.SeeINDEXforadditionalinformationonitsUNIQUEoption. Nullvaluesandduplicaterecordsarenotpermittedinafieldusedforaprimaryorcandidateindex.However,VisualFoxProwillnotgenerateanerrorifyoucreateaprimaryorcandidateindexforafieldthatsupportsnullvalues.VisualFoxProwillgenerateanerrorifyouattempttoenteranullorduplicatevalueintoafieldusedforaprimaryorcandidateindex.
- REFERENCESTableName2[TAGTagName1]
- Specifiestheparenttabletowhichapersistentrelationshipisestablished.IfyouomitTAGTagName1,therelationshipisestablishedusingtheprimaryindexkeyoftheparenttable.Iftheparenttabledoesnothaveaprimaryindex,VisualFoxProgeneratesanerror.
IncludeTAGTagName1toestablisharelationbasedonanexistingindextagfortheparenttable.Indextagnamescancontainupto10characters.
Theparenttablecannotbeafreetable.
- NOCPTRANS
- Preventstranslationtoadifferentcodepageforcharacterandmemofields.Ifthetableisconvertedtoanothercodepage,thefieldsforwhichNOCPTRANShasbeenspecifiedarenottranslated.NOCPTRANScanonlybespecifiedforcharacterandmemofields.ThiswillcreatewhatappearsintheTableDesignerasCharacter(binary)andMemo(binary)datatypes.
ThefollowingexamplecreatesatablenamedMYTABLEcontainingtwocharacterfieldsandtwomemofields.ThesecondcharacterfieldCHAR2andthesecondmemofieldMEMO2includeNOCPTRANStopreventtranslation.
CREATETABLEmytable(char1C(10),char2C(10)NOCPTRANS,;memo1M,memo2MNOCPTRANS) - PRIMARYKEYeExpression2TAGTagName2
- Specifiesaprimaryindextocreate.eExpression2specifiesanyfieldorcombinationoffieldsinthetable.TAGTagName2specifiesthenamefortheprimaryindextagthatiscreated.Indextagnamescancontainupto10characters.
Becauseatablecanhaveonlyoneprimaryindex,youcannotincludethisclauseifyouhavealreadycreatedaprimaryindexforafield.VisualFoxProgeneratesanerrorifyouincludemorethanonePRIMARYKEYclauseinCREATETABLE.
- UNIQUEeExpression3TAGTagName3
- Createsacandidateindex.eExpression3specifiesanyfieldorcombinationoffieldsinthetable.However,ifyouhavecreatedaprimaryindexwithoneofthePRIMARYKEYoptions,youcannotincludethefieldthatwasspecifiedfortheprimaryindex.TAGTagName3specifiesatagnameforthecandidateindextagthatiscreated.Indextagnamescancontainupto10characters.
Atablecanhavemultiplecandidateindexes.
- FOREIGNKEYeExpression4TAGTagName4[NODUP]
- Createsaforeign(non-primary)index,andestablishesarelationshiptoaparenttable.eExpression4specifiestheforeignindexkeyexpressionandTagName4specifiesthenameoftheforeignindexkeytagthatiscreated.Indextagnamescancontainupto10characters.IncludeNODUPtocreateacandidateforeignindex.
Youcancreatemultipleforeignindexesforthetable,buttheforeignindexexpressionsmustspecifydifferentfieldsinthetable.
- REFERENCESTableName3[TAGTagName5]
- Specifiestheparenttabletowhichapersistentrelationshipisestablished.IncludeTAGTagName5toestablisharelationbasedonanindextagfortheparenttable.Indextagnamescancontainupto10characters.IfyouomitTAGTagName5,therelationshipisestablishedusingtheparenttable'sprimaryindexkeybydefault.
- CHECKeExpression2[ERRORcMessageText2]
- Specifiesthetablevalidationrule.ERRORcMessageText2specifiestheerrormessageVisualFoxProdisplayswhenthetablevalidationruleisexecuted.ThemessageisdisplayedonlywhendataischangedwithinaBrowsewindoworEditwindow.
- FROMARRAYArrayName
- Specifiesthenameofanexistingarraywhosecontentsarethename,type,precision,andscaleforeachfieldinthetable.ThecontentsofthearraycanbedefinedwiththeAFIELDS( )function.
Thenewtableisopenedinthelowestavailableworkarea,andcanbeaccessedbyitsalias.Thenewtableisopenedexclusively,regardlessofthecurrentsettingofSETEXCLUSIVE.
Ifadatabaseisopenandyoudon'tincludetheFREEclause,thenewtableisaddedtothedatabase.Youcannotcreateanewtablewiththesamenameasatableinthedatabase.
Ifadatabaseisn'topenwhenyoucreatethenewtable,includingtheNAME,CHECK,DEFAULT,FOREIGNKEY,PRIMARYKEY,orREFERENCESclausesgeneratesanerror.
NotethattheCREATETABLEsyntaxusescommastoseparatecertainCREATETABLEoptions.Also,theNULL,NOTNULL,CHECK,DEFAULT,PRIMARYKEYandUNIQUEclausemustbeplacedwithintheparenthesescontainingthecolumndefinitions.
Thefollowingexamplecreatesanewdatabasenamed
CREATETABLE
salesman;(SalesIDc(6)PRIMARYKEY,;SaleNameC(20))*Createacustomertableandrelateittothesalesmantable.CREATETABLE
customer;(SalesIDc(6),;CustIdiPRIMARYKEY,;CustNamec(20)UNIQUE,;SalesBranchc(3),;FOREIGNKEY
SalesIdTAGSalesIdREFERENCES
salesman)*Createanorderstablerelatedtocustomerwithitsownprimary*keyandsomebusinessrulessuchasdefaults&checks.CREATETABLE
orders;(OrderIdiPRIMARYKEY,;CustIdiREFERENCES
customerTAGCustId,;OrderAmty(4),;OrderQtyi;DEFAULT
10;CHECK
(OrderQty>9);ERROR
"OrderQuantitymustbeatleast10",;DiscPercentn(6,2)NULL;DEFAULT
.NULL.,;CHECK
(OrderAmt>0)ERROR
"OrderAmountMustbe>0")*Displaynewdatabase,tables,andrelationshipsMODIFYDATABASE*DeleteexamplefilesSETSAFETYOFF&&TosuppressverificationmessageCLOSEDATABASES&&ClosedatabasebeforedeletingDELETEDATABASEmydata1DELETETABLES- CREATETABLE–SQLCommand
- sqlcommand
- SqlCommand
- sqlcommand
- sqlcommand
- CreateTable - sqlite
- Yii2 createTable
- CreateTable FieldDefs AddFieldDef
- hbase的createTable
- HBase Admin createTable 创建表
- JSQLParser源码分析之CreateTable
- 什么是sqlcommand
- 关于SqlCommand
- SqlCommand对象
- 几个SQLCommand
- sqlcommand 使用方法
- SqlCommand对象
- SqlCommand 应用
- 如何恢复系统?
- WebPage类的源代码
- 使用SQL-DMO备份并进行校验
- Ubuntu 8.04 LTS - 从这里开始
- C# 程序——获得外网IP,MAC,本地IP,子网掩码实例
- CREATETABLE–SQLCommand
- 实用的存储过程之一
- 求助问题
- Session登陆后丢失解决方法
- 跟我学SQL:串行数据类型
- J2me 网络问题 汇总
- 网络与通讯编程集锦
- 跟我学SQL:创建和修改表格
- 概述Java Web基础