SQLColumn[…]
represents a column in an SQL table.
Details and Options
Examples
Basic Examples
Options
"DataTypeName"
"DataLength"
"Default"
"Nullable"
"PrimaryKey"
See Also
Tech Notes
DatabaseLink`
DatabaseLink`
SQLColumn
SQLColumn[…]
represents a column in an SQL table.
Details and Options
- To use SQLColumn, you first need to load DatabaseLink using Needs["DatabaseLink`"].
- The following options can be given:
-
"DataTypeName" None type of the entry "DataLength" None maximum length for variable length data "Default" None default value for column "Nullable" False whether the entry can be null "PrimaryKey" False indicates a primary key column
Examples
open all close allBasic Examples (1)
Needs["DatabaseLink`"]If you find that the examples in this section do not work as shown, you may need to install or restore the example database with the "DatabaseLink`DatabaseExamples`" package, as described in Using the Example Databases.
conn = OpenSQLConnection["demo"];SQLColumns[conn, "SAMPLETABLE1"]Select data matching a condition:
SQLSelect[conn, "SAMPLETABLE1", SQLColumn["VALUE"] > 6]SQLExecute[conn, "SELECT `1` FROM `2`", {SQLArgument[SQLColumn["VALUE"], SQLColumn["NAME"]], SQLTable["SAMPLETABLE1"]}]CloseSQLConnection[conn];If you find that the examples in this section do not work as shown, you may need to install or restore the example database with the "DatabaseLink`DatabaseExamples`" package, as described in Using the Example Databases.
Options (5)
"DataTypeName" (1)
Needs["DatabaseLink`"]Specify data types for columns:
conn = OpenSQLConnection["demo"];SQLCreateTable[conn, SQLTable["TEST"],
{
SQLColumn["TINYINTCOL", "DataTypeName" -> "TINYINT"],
SQLColumn["SMALLINTCOL", "DataTypeName" -> "SMALLINT"],
SQLColumn["INTEGERCOL", "DataTypeName" -> "INTEGER"],
SQLColumn["BIGINTCOL", "DataTypeName" -> "BIGINT"],
SQLColumn["NUMERICCOL", "DataTypeName" -> "NUMERIC"], SQLColumn["DECIMALCOL", "DataTypeName" -> "DECIMAL"],
SQLColumn["FLOATCOL", "DataTypeName" -> "FLOAT"],
SQLColumn["REALCOL", "DataTypeName" -> "REAL"],
SQLColumn["DOUBLECOL", "DataTypeName" -> "DOUBLE"], SQLColumn["BITCOL", "DataTypeName" -> "BIT"],
SQLColumn["LONGVARBINARYCOL", "DataTypeName" -> "LONGVARBINARY"],
SQLColumn["VARBINARYCOL", "DataTypeName" -> "VARBINARY", "DataLength" -> 1000],
SQLColumn["BINARYCOL", "DataTypeName" -> "BINARY"],
SQLColumn["LONGVARCHARCOL", "DataTypeName" -> "LONGVARCHAR"],
SQLColumn["VARCHARCOL", "DataTypeName" -> "VARCHAR", "DataLength" -> 5], SQLColumn["CHARCOL", "DataTypeName" -> "CHAR", "DataLength" -> 3],
SQLColumn["DATECOL", "DataTypeName" -> "DATE"], SQLColumn["TIMECOL", "DataTypeName" -> "TIME"],
SQLColumn["TIMESTAMPCOL", "DataTypeName" -> "TIMESTAMP"],
SQLColumn["OBJECTCOL", "DataTypeName" -> "OBJECT"]
}];SQLDropTable[conn, "TEST"];CloseSQLConnection[conn];"DataLength" (1)
Needs["DatabaseLink`"]Specify data lengths for appropriate types:
conn = OpenSQLConnection["demo"];SQLCreateTable[conn, SQLTable["TEST"], {SQLColumn["X", "DataTypeName" -> "VARCHAR", "DataLength" -> 5], SQLColumn["Y", "DataTypeName" -> "CHAR", "DataLength" -> 3]}];SQLDropTable[conn, "TEST"];CloseSQLConnection[conn];"Default" (1)
Needs["DatabaseLink`"]conn = OpenSQLConnection["demo"];SQLCreateTable[conn, SQLTable["TEST"], {SQLColumn["X", "DataTypeName" -> "TINYINT", "Default" -> -1], SQLColumn["Y", "DataTypeName" -> "TIME", "Default" -> "00:00:00"]}];SQLDropTable[conn, "TEST"];CloseSQLConnection[conn];"Nullable" (1)
Needs["DatabaseLink`"]conn = OpenSQLConnection["demo"];SQLCreateTable[conn, SQLTable["TEST"], {SQLColumn["A", "DataTypeName" -> "Integer", "Nullable" -> True], SQLColumn["B", "DataTypeName" -> "Integer", "Nullable" -> False]}];SQLDropTable[conn, "TEST"];CloseSQLConnection[conn];"PrimaryKey" (1)
Needs["DatabaseLink`"]conn = OpenSQLConnection[JDBC["SQLite(Memory)", "scratch"]];SQLCreateTable[conn, SQLTable["TEST"], {SQLColumn["X", "DataTypeName" -> "INTEGER", "PrimaryKey" -> True], SQLColumn["Y", "DataTypeName" -> "CHAR", "DataLength" -> 3]}];SQLTablePrimaryKeys[conn, "TEST", "ShowColumnHeadings" -> True]SQLDropTable[conn, "TEST"];CloseSQLConnection[conn];