CREATE TABLE(SQL 图形)CREATE TABLE (SQL Graph)

适用于:Applies to: 是SQL Server 2017 (14.x)SQL Server 2017 (14.x)yesSQL Server 2017 (14.x)SQL Server 2017 (14.x) 及更高版本适用于:Applies to: 是SQL Server 2017 (14.x)SQL Server 2017 (14.x)yesSQL Server 2017 (14.x)SQL Server 2017 (14.x) and later

NODEEDGE 表的形式创建新 SQL 图形表。Creates a new SQL graph table as either a NODE or an EDGE table.

备注

有关标准 Transact-SQL 语句,请参阅 CREATE TABLE (Transact-SQL)For standard Transact-SQL statements, see CREATE TABLE (Transact-SQL).

主题链接图标 Transact-SQL 语法约定Topic link icon Transact-SQL Syntax Conventions

语法Syntax

CREATE TABLE   
    { database_name.schema_name.table_name | schema_name.table_name | table_name }
    ( { <column_definition> } 
       | <computed_column_definition>
       | <column_set_definition>
       | [ <table_constraint> ] [ ,... n ]
       | [ <table_index> ] }
          [ ,...n ]
    )   
    AS [ NODE | EDGE ]
    [ ON { partition_scheme_name ( partition_column_name )
           | filegroup
           | "default" } ]
[ ; ] 

< table_constraint > ::=
[ CONSTRAINT constraint_name ]
{
    { PRIMARY KEY | UNIQUE }
        [ CLUSTERED | NONCLUSTERED ]
        (column [ ASC | DESC ] [ ,...n ] )
        [
            WITH FILLFACTOR = fillfactor
           |WITH ( <index_option> [ , ...n ] )
        ]
        [ ON { partition_scheme_name (partition_column_name)
            | filegroup | "default" } ]
    | FOREIGN KEY
        ( column [ ,...n ] )
        REFERENCES referenced_table_name [ ( ref_column [ ,...n ] ) ]
        [ ON DELETE { NO ACTION | CASCADE | SET NULL | SET DEFAULT } ]
        [ ON UPDATE { NO ACTION | CASCADE | SET NULL | SET DEFAULT } ]
        [ NOT FOR REPLICATION ]
    | CONNECTION
        ( { node_table TO node_table } 
          [ , {node_table TO node_table }]
          [ , ...n ]
        )
        [ ON DELETE { NO ACTION | CASCADE } ]
    | CHECK [ NOT FOR REPLICATION ] ( logical_expression )

备注

若要查看 SQL Server 2014 及更早版本的 Transact-SQL 语法,请参阅早期版本文档To view Transact-SQL syntax for SQL Server 2014 and earlier, see Previous versions documentation.

参数Arguments

本文档仅列出与 SQL 图形相关的参数。This document lists only arguments pertaining to SQL graph. 有关受支持参数的完整列表和说明,请参阅 CREATE TABLE (Transact-SQL)For a full list and description of supported arguments, see CREATE TABLE (Transact-SQL)

database_name database_name
要在其中创建表的数据库的名称。Is the name of the database in which the table is created. database_name 须指定现有数据库的名称。database_name must specify the name of an existing database. 如果未指定,则 database_name 默认为当前数据库。If not specified, database_name defaults to the current database. 当前连接的登录名必须与 database_name 所指定数据库中的一个现有用户 ID 关联,并且该用户 ID 必须具有 CREATE TABLE 权限。The login for the current connection must be associated with an existing user ID in the database specified by database_name, and that user ID must have CREATE TABLE permissions.

schema_name schema_name
新表所属架构的名称。Is the name of the schema to which the new table belongs.

table_name table_name
是节点或边界表的名称。Is the name of the node or edge table. 表名必须遵循有关标识符的规则。Table names must follow the rules for identifiers. 除了本地临时表名(以单个数字符号 (#) 为前缀的名称)不能超过 116 个字符外,table_name 最多可包含 128 个字符。table_name can be a maximum of 128 characters, except for local temporary table names (names prefixed with a single number sign (#)) that cannot exceed 116 characters.

NODENODE
创建节点表。Creates a node table.

EDGEEDGE
创建边界表。Creates an edge table.

table_constraint table_constraint
指定添加到表中的 PRIMARY KEY、UNIQUE、FOREIGN KEY、CONNECTION constraint、CHECK 约束或 DEFAULT 定义的属性。Specifies the properties of a PRIMARY KEY, UNIQUE, FOREIGN KEY, CONNECTION constraint, a CHECK constraint, or a DEFAULT definition added to a table.

备注

CONNECTION 约束仅适用于边缘表类型。CONNECTION constraint applies only to an edge table type.

ON { partition_scheme | filegroup | "default" }ON { partition_scheme | filegroup | "default" }
指定存储表的分区架构或文件组。Specifies the partition scheme or filegroup on which the table is stored. 如果指定了 partition_scheme,则该表将成为已分区表,其分区存储在 partition_scheme 所指定的一个或多个文件组的集合中。If partition_scheme is specified, the table is to be a partitioned table whose partitions are stored on a set of one or more filegroups specified in partition_scheme. 如果指定了 filegroup,则该表将存储在已命名文件组中。If filegroup is specified, the table is stored in the named filegroup. 数据库中必须存在该文件组。The filegroup must exist within the database. 如果指定了 default,或者根本未指定 ON,则该表将存储在默认文件组中。If "default" is specified, or if ON is not specified at all, the table is stored on the default filegroup. CREATE TABLE 中指定的表的存储机制以后不能进行更改。The storage mechanism of a table as specified in CREATE TABLE cannot be subsequently altered.

ON {partition_scheme | filegroup | "default"}ON {partition_scheme | filegroup | "default"}
也可在 PRIMARY KEY 约束或 UNIQUE 约束中指定。Can also be specified in a PRIMARY KEY or UNIQUE constraint. 这些约束会创建索引。These constraints create indexes. 如果 filegroup 未指定,则索引会存储在已命名文件组中。If filegroup is specified, the index is stored in the named filegroup. 如果指定了 default,或者根本未指定 ON,则索引将与表存储在同一文件组中。If "default" is specified, or if ON is not specified at all, the index is stored in the same filegroup as the table. 如果 PRIMARY KEY 约束或 UNIQUE 约束创建聚集索引,则表的数据页将与索引存储在同一文件组中。If the PRIMARY KEY or UNIQUE constraint creates a clustered index, the data pages for the table are stored in the same filegroup as the index. 如果指定了 CLUSTERED 或约束另外创建了聚集索引,并且指定的 partition_scheme 不同于表定义的 partition_scheme 或 filegroup,或反之,则只接受约束定义,而忽略其他定义。If CLUSTERED is specified or the constraint otherwise creates a clustered index, and a partition_scheme is specified that differs from the partition_scheme or filegroup of the table definition, or vice-versa, only the constraint definition will be honored, and the other will be ignored.

备注Remarks

不支持以节点或边界表的形式创建临时表。Creating a temporary table as node or edge table is not supported.

不支持以临时表的形式创建节点或边界表。Creating a node or edge table as a temporal table is not supported.

节点或边界表不支持延伸数据库。Stretch database is not supported for node or edge table.

节点或边界表不能是外部表(PolyBase 不支持图形表)。Node or edge tables cannot be external tables (no PolyBase support for graph tables).

未分区的图节点/边界表不能更改为分区图节点/边界表。A non-partitioned graph node/edge table cannot be altered into a partitioned graph node/edge table.

示例Examples

A.A. 创建 NODECreate a NODE table

下面的示例演示如何创建 NODEThe following example shows how to create a NODE table

 CREATE TABLE Person (
        ID INTEGER PRIMARY KEY, 
        name VARCHAR(100), 
        email VARCHAR(100)
 ) AS NODE;

B.B. 创建 EDGECreate an EDGE table

下面的示例演示如何创建 EDGEThe following examples show how to create EDGE tables

 CREATE TABLE friends (
    id INTEGER PRIMARY KEY,
    start_date DATe
 ) AS EDGE;
 -- Create a likes edge table, this table does not have any user defined attributes   
 CREATE TABLE likes AS EDGE;

下一个示例建模了一条规则,即只有用户可以和其他用户进行联结,这意味着此边界不允许引用除人员之外的任何节点。The next example models a rule that only people can be friends with other people, which means this edge does not allow reference to any node other than Person.

/* Create friend edge table with CONSTRAINT, restricts for nodes and it direction */
CREATE TABLE dbo.FriendOf(
  CONSTRAINT cnt_Person_FriendOf_Person
    CONNECTION (dbo.Person TO dbo.Person) 
)AS EDGE;

另请参阅See Also

ALTER TABLE table_constraint ALTER TABLE table_constraint
ALTER TABLE (Transact-SQL) ALTER TABLE (Transact-SQL)
INSERT(SQL 图形)]INSERT (SQL Graph)]
使用 SQL Server 2017 进行图形处理Graph processing with SQL Server 2017