Send feedback on this topic.
Teradata.Client.Provider
SmallInt Data Type
.NET Data Provider for Teradata > Developer's Guide > Data Types > Numeric Data Types > SmallInt Data Type

Schema Collections

The Schema collections return metadata for the Teradata Database objects. The notable metadata columns for the SmallInt data type are:

Column Name Description

COLUMN_TYPE

or

DATA_TYPE

Set to SMALLINT.
NUMERIC_PRECISION Set to 5.
FORMAT Teradata Database Format assigned to the Teradata Database object.
PROVIDERDBTYPE It is set to TdType.SmallInt.

Schema Table

The TdDataReader.GetSchemaTable returns result set metadata. The notable metadata columns for the SmallInt data type are:

Column Name Description
NumericPrecision Set to 5.
DataType System.Type object for the System.Int16 type.
ProviderType Set to TdType.SmallInt.
Format Teradata Database Format assigned to the Teradata Database object.
ProviderSpecificDataType System.Type object for the System.Int16 structure.
Note

The Data Provider does not have a Provider Specific Type corresponding to the SmallInt Data Type. The Data Provider returns System.Int16 data type from the Provider Specific Value methods.

Configuring Parameters

The following example shows how to configure a SmallInt  parameter using DbType type declaration and a BCL value.

C#
Copy Code
TdParameter quantity = new TdParameter();

quantity.DbType = DbType.Int16;

quantity.Value = 10;

The following example shows how to configure a  SmallInt parameter using TdType type declaration and a BCL value.

C#
Copy Code
TdParameter quantity = new TdParameter();

quantity.TdType = TdType.SmallInt;

quantity.Value = 10;

Specifying SmallInt as Literal

The syntax for the SmallInt Literal ±ddddd. SmallInt literals consist of an optional sign (+ or -) followed by at most five digits. Integer values ranging from -32768 to -129 and 128 to 32767 are considered a SmallInt type.

Note

We recommend to always use Parameters in order to take advantage of the Teradata Database Request Cache.

The following example shows 200 represented as SmallInt-Literal in the Command Text.

C#
Copy Code
using (TdConnection cn = new TdConnection("data source=x;UserId=y;Password=z;"))
{
    cn.Open();
    TdCommand cmd = cn.CreateCommand();

    cmd.CommandText = "SELECT Id, orderDate from Order where quantity > 200  ";

    using (TdDataReader reader = cmd.ExecuteReader())
    {
        if (reader.HasRows)
        {
            while (reader.Read())
            {
                Console.WriteLine("Id={0}, orderDate={1}", reader.GetInt64(0), reader.GetDate(1));
            }
        }
    }
}

Retrieving SmallInt Data

The following methods and properties return the column or parameter value as a System.Int16 structure.

  1. TdDataReader.GetInt16
  2. TdDataReader.GetValue
  3. TdDataReader.GetFieldValue<Int16>
  4. TdParameter.Value
  5. TdParameter.GetValue<Int16>

The following Provider Specific Value method and property return the column or parameter value as a System.Int16 structure.

Note

The Data Provider does not have a Provider Specific Type corresponding to the SmallInt Data Type. The Data Provider returns System.Int16 data type from the Provider Specific Value methods.

  1. TdDataReader.GetProviderSpecificValue
  2. TdParameter.ProviderSpecificValue

C#
Copy Code
using (TdConnection cn = new TdConnection("data source=DS1;UserId=Joe;Password=XY;"))
{
    cn.Open();

    TdCommand cmd = cn.CreateCommand();
    cmd.CommandText = "SELECT Id, Quantity from Order where Quantity > ?";
    cmd.Parameters.Add("quantity", TdType.SmallInt);
    cmd.Parameters["quantity"].Value = 200;

    using (TdDataReader reader = cmd.ExecuteReader())
    {
        if (reader.HasRows)
        {
            while (reader.Read())
            {
                Console.WriteLine("[System.Int16] Quantity = {0}", reader.GetInt16(1).ToString());
            }
        }
    }
}

/* Output:
    [System.Int16] Quantity = 205
*/

See Also

Data Type Mappings

Accessor Methods for Retrieving Data

Configuring Parameters and Parameter Data Types