SQLCreateTable[conn,table,columns]
creates a new table in an SQL connection.
更多信息和选项
范例
基本范例
Options
"Index"
参见
技术笔记
相关指南
DatabaseLink`
DatabaseLink`
SQLCreateTable
SQLCreateTable[conn,table,columns]
creates a new table in an SQL connection.
更多信息和选项
- To use SQLCreateTable, you first need to load DatabaseLink using Needs["DatabaseLink`"].
- SQLCreateTable returns an integer specifying the number of rows affected by the query. If the table is created correctly, this integer will always be zero, as no rows are affected when creating a new table.
- The following options can be given:
-
"Timeout" $SQLTimeout the timeout for the query "Index" None column(s) to index
范例
打开所有单元 关闭所有单元基本范例 (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"];SQLCreateTable[conn, SQLTable["TEST1"], {SQLColumn["A", "DataTypeName" -> "Integer"], SQLColumn["B", "DataTypeName" -> "Integer"]}]Specify whether columns can have null values:
SQLCreateTable[conn, SQLTable["TEST2"], {SQLColumn["C", "DataTypeName" -> "Integer", "Nullable" -> True], SQLColumn["D", "DataTypeName" -> "Integer", "Nullable" -> False]}]SQLCreateTable[conn, SQLTable["TEST3"],
{
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" -> 100],
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"]
}]SQLCreateTable[conn, SQLTable["TEST4"], {SQLColumn["X", "DataTypeName" -> "VARCHAR", "DataLength" -> 5], SQLColumn["Y", "DataTypeName" -> "CHAR", "DataLength" -> 3]}]SQLDropTable[conn, "TEST1"];SQLDropTable[conn, "TEST2"];SQLDropTable[conn, "TEST3"];SQLDropTable[conn, "TEST4"];CloseSQLConnection[conn];Options (1)
"Index" (1)
Needs["DatabaseLink`"]Supply column to be indexed. The index type will depend on database defaults:
conn = OpenSQLConnection["demo"];SQLCreateTable[conn, SQLTable["TEST1"], {SQLColumn["id", "DataTypeName" -> "Integer", "PrimaryKey" -> True], SQLColumn["Name", "DataTypeName" -> "VARCHAR", "DataLength" -> 255]},
"Index" -> "Name"]SQLTableIndexInformation[conn, "TEST1", "ShowColumnHeadings" -> True]//TableFormSQLCreateTable[conn, SQLTable["TEST2"], {SQLColumn["id", "DataTypeName" -> "Integer", "PrimaryKey" -> True],
SQLColumn["Name", "DataTypeName" -> "VARCHAR", "DataLength" -> 255],
SQLColumn["Age", "DataTypeName" -> "INTEGER"]},
"Index" -> {"Name", "Age"}]SQLTableIndexInformation[conn, "TEST2", "ShowColumnHeadings" -> True]//TableFormSQLDropTable[conn, "TEST1"];SQLDropTable[conn, "TEST2"];CloseSQLConnection[conn];