Sei sulla pagina 1di 4

12/17/2016

CREATECURSORSQLCommand

CREATE CURSOR SQL Command


Visual Studio .NET 2003
Creates a temporary table.

CREATECURSORalias_name
(fname1type[(precision[,scale])][NULL|NOTNULL]
[CHECKlExpression[ERRORcMessageText]]
[AUTOINC[NEXTVALUENextValue[STEPStepValue]]]
[DEFAULTeExpression][UNIQUE[COLLATEcCollateSequence]]
[NOCPTRANS][,fname2...])
|FROMARRAYArrayName

Parameters
alias_name
Specifies the name of the temporary table to create. The alias_name parameter can be a name expression.
fname
Specifies the name of a field in the temporary table. Each fname can be a name expression.
type
Specifies a single letter indicating the data type for the field.
precision
Specifies the width of the field specified with fname. Some data types require that you specify a value for precision.
scale
Specifies the number of decimal places for the specified data type. Some data types require that you specify a value for
scale.
The following table shows what type, precision, and scale can be.

FieldType

nFieldWidth

nPrecision

Description

Character field of width n

Date

Datetime

Numeric field of width n with d decimal places

Floating numeric field of width n with d decimal


places

Integer

Double

Currency

https://msdn.microsoft.com/enus/library/aa977464(d=printer,v=vs.71).aspx

1/4

12/17/2016

CREATECURSORSQLCommand

Logical

Memo

General

Picture

The nFieldWidth and nPrecision parameters are ignored for D, T, Y, L, M, G, and P types. The nPrecision parameter defaults
to zero no decimal places if nPrecision is not included for the N, F, or B types.
NULL | NOT NULL
Specifies whether null values are allowed in the field. NULL permits null values, while NOT NULL does not allow null
values.
CHECK lExpression
Specifies a validation rule for the field. The lExpression parameter must evaluate to a logical expression and can be a user
defined function or a stored procedure.
ERROR cMessageText
Specifies an error message. Visual FoxPro displays this message when the validation rule specified in the CHECK clause
generates an error. The message displays only when data is changed within a Browse window or Edit window.
AUTOINC [NEXTVALUE NextValue [STEP StepValue]]
Enables autoincrementing for the field.
NextValue specifies the start value and can be a positive or a negative integer value ranging from 2,147,483,647 to
2,147,483,647. The default value is 1. You can set NextValue using the Next Value box on the Fields tab in the Table
Designer.
StepValue specifies the increment value for the field and can be a positive, nonzero integer value ranging from 1 to 255.
The default value is 1. You can set StepValue using the Step box on the Fields tab in the Table Designer.
Autoincrementing values cannot be null .NULL..
NoteTables containing automatically incrementing field values append tablebuffered records
approximately 35% slower than tables without automatically incrementing field values, which might affect
performance. When using table buffering, the table header is locked when the record is appended.
DEFAULT eExpression
Specifies a default value for the field. The data type of eExpression must be the same as the specified field's data type.
If you use the AUTOINC clause to turn on autoincrementing for a field and specify a default value, Visual FoxPro stores
the default value in the table but does not use it. Visual FoxPro uses the default value if you use the ALTER TABLE SQL
command to remove autoincrementing for the field.
UNIQUE
Creates a candidate index for the field. The candidate index tag has the same name as the field. For more information
about candidate indexes, see Index Information Display and Setting a Primary or Candidate Index.
COLLATE cCollateSequence
Specifies a collation sequence other than the default setting, MACHINE. The cCollateSequence parameter must be a valid
Visual FoxPro collation sequence. For more information about setting collation sequences, see Optimization of
International Applications and SET COLLATE Command.
NOCPTRANS
Prevents translation to a different code page for character and memo fields. You can specify NOCPTRANS only for
character and memo fields.
FROM ARRAY ArrayName
Specifies the name of an existing array whose contents are the name, type, precision, and scale for each field in the
temporary table. You can use the FROM ARRAY clause instead of specifying individual fields. For the proper format of
the contents of the array, see AFIELDS Function.
https://msdn.microsoft.com/enus/library/aa977464(d=printer,v=vs.71).aspx

2/4

12/17/2016

CREATECURSORSQLCommand

Autoincrementing is turned on when the step value is greater than 0.

Remarks
CREATE CURSOR creates a temporary table that exists until it is closed. You can manipulate a temporary table created with
CREATE CURSOR like any other table you can browse and index it, and you can append and modify records.
The temporary table opens in the lowest numbered available unused work area and can be accessed by its alias. Each field in
the temporary table is defined with a name, type, precision, and scale. These definitions can be obtained from the command
itself or from an array. The temporary table opens exclusively, regardless of the setting of SET EXCLUSIVE.
If you omit NULL and NOT NULL, the current setting of SET NULL determines if null values are allowed in the field. However, if
you omit NULL and NOT NULL and include the PRIMARY KEY or UNIQUE clause, Visual FoxPro disregards the current setting
of SET NULL, and the field defaults to NOT NULL.
Null values and duplicate records are not permitted in a field used for a candidate index. However, Visual FoxPro does not
generate an error if you create a candidate index for a field that supports null values. Visual FoxPro generates an error if you
attempt to enter a null or duplicate value into a field used for a candidate index.
NoteCandidate indexes, created by including the UNIQUE option provided for ANSI compatibility in CREATE
TABLE SQL or ALTER TABLE SQL commands, are not the same as indexes created in the INDEX command
with the UNIQUE option. An index created in the INDEX command using the UNIQUE option allows duplicate
index keys; candidate indexes do not allow duplicate index keys. For more information about the UNIQUE option
in the INDEX command, see INDEX Command.
If the table is converted to another code page, the fields for which NOCPTRANS has been specified are not translated.
CREATE CURSOR...FROM ARRAY recognizes all the fields available in the AFIELDS function and turns on autoincrementing in
the cursor when the Step value is greater than zero.

Example
The following example creates a cursor with the alias "employee". A blank record is appended, filled, and displayed with the
BROWSE command.

CLOSEDATABASES
CLEAR
CREATECURSORemployee;
(EmpIDN(5),NameC(20),AddressC(30),CityC(30),;
PostalCodeC(10),OfficeNoC(8)NULL,SpecialtyM)
DISPLAYSTRUCTURE
WAITWINDOW"Pressakeytoaddarecord."
INSERTINTOemployee(EmpId,Name,Address,City,PostalCode,;
OfficeNo,Specialty);
VALUES(1002,"Dr.BonnieDoren","UniversityofOregon","Eugene",;
"98403","","SecondarySpecialEducation")
BROWSE
*Atthispointyoucancopythisrecordtoapermanenttable.
CLOSEALL&&Oncethecursorcloses,alldataisflushedfrommemory.
CLEAR
The following example uses NOCPTRANS to prevent translation to a different code page. The example creates a cursor named
"mycursor" that contains two character fields and two memo fields. The second character field, "char2", and the second memo
https://msdn.microsoft.com/enus/library/aa977464(d=printer,v=vs.71).aspx

3/4

12/17/2016

CREATECURSORSQLCommand

field, "memo2", include NOCPTRANS to prevent translation.

CREATECURSORmycursor(char1C(10),char2C(10)NOCPTRANS,;
memo1M,memo2MNOCPTRANS)

See Also
AFIELDS | CREATE | CREATE QUERY | CREATE TABLE SQL | INSERT SQL | MODIFY QUERY | SELECT SQL
2016 Microsoft

https://msdn.microsoft.com/enus/library/aa977464(d=printer,v=vs.71).aspx

4/4

Potrebbero piacerti anche