如何使用SQL语句创建表,要完整的语句。
1个回答
展开全部
自己打开企业管理器,随便找个表,导出一个创建表的脚本,就什么都有了。
要语法,SQL的联机帮助里就有:
CREATE
TABLE
[
database_name
.
[
schema_name
]
.
|
schema_name
.
]
table_name
(
{
|
}
[
]
[
,...n
]
)
[
ON
{
partition_scheme_name
(
partition_column_name
)
|
filegroup
|
"default"
}
]
[
{
TEXTIMAGE_ON
{
filegroup
|
"default"
}
]
[
;
]
::=
column_name
[
COLLATE
collation_name
]
[
NULL
|
NOT
NULL
]
[
[
CONSTRAINT
constraint_name
]
DEFAULT
constant_expression
]
|
[
IDENTITY
[
(
seed
,increment
)
]
[
NOT
FOR
REPLICATION
]
]
[
ROWGUIDCOL
]
[
[
...n
]
]
::=
[
type_schema_name
.
]
type_name
[
(
precision
[
,
scale
]
|
max
|
[
{
CONTENT
|
DOCUMENT
}
]
xml_schema_collection
)
]
::=
[
CONSTRAINT
constraint_name
]
{
{
PRIMARY
KEY
|
UNIQUE
}
[
CLUSTERED
|
NONCLUSTERED
]
[
WITH
FILLFACTOR
=
fillfactor
|
WITH
(
<
index_option
>
[
,
...n
]
)
]
[
ON
{
partition_scheme_name
(
partition_column_name
)
|
filegroup
|
"default"
}
]
|
[
FOREIGN
KEY
]
REFERENCES
[
schema_name
.
]
referenced_table_name
[
(
ref_column
)
]
[
ON
DELETE
{
NO
ACTION
|
CASCADE
|
SET
NULL
|
SET
DEFAULT
}
]
[
ON
UPDATE
{
NO
ACTION
|
CASCADE
|
SET
NULL
|
SET
DEFAULT
}
]
[
NOT
FOR
REPLICATION
]
|
CHECK
[
NOT
FOR
REPLICATION
]
(
logical_expression
)
}
::=
column_name
AS
computed_column_expression
[
PERSISTED
[
NOT
NULL
]
]
[
[
CONSTRAINT
constraint_name
]
{
PRIMARY
KEY
|
UNIQUE
}
[
CLUSTERED
|
NONCLUSTERED
]
[
WITH
FILLFACTOR
=
fillfactor
|
WITH
(
[
,
...n
]
)
]
|
[
FOREIGN
KEY
]
REFERENCES
referenced_table_name
[
(
ref_column
)
]
[
ON
DELETE
{
NO
ACTION
|
CASCADE
}
]
[
ON
UPDATE
{
NO
ACTION
}
]
[
NOT
FOR
REPLICATION
]
|
CHECK
[
NOT
FOR
REPLICATION
]
(
logical_expression
)
[
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
(
[
,
...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
]
|
CHECK
[
NOT
FOR
REPLICATION
]
(
logical_expression
)
}
::=
{
PAD_INDEX
=
{
ON
|
OFF
}
|
FILLFACTOR
=
fillfactor
|
IGNORE_DUP_KEY
=
{
ON
|
OFF
}
|
STATISTICS_NORECOMPUTE
=
{
ON
|
OFF
}
|
ALLOW_ROW_LOCKS
=
{
ON
|
OFF}
|
ALLOW_PAGE_LOCKS
={
ON
|
OFF}
}
要语法,SQL的联机帮助里就有:
CREATE
TABLE
[
database_name
.
[
schema_name
]
.
|
schema_name
.
]
table_name
(
{
|
}
[
]
[
,...n
]
)
[
ON
{
partition_scheme_name
(
partition_column_name
)
|
filegroup
|
"default"
}
]
[
{
TEXTIMAGE_ON
{
filegroup
|
"default"
}
]
[
;
]
::=
column_name
[
COLLATE
collation_name
]
[
NULL
|
NOT
NULL
]
[
[
CONSTRAINT
constraint_name
]
DEFAULT
constant_expression
]
|
[
IDENTITY
[
(
seed
,increment
)
]
[
NOT
FOR
REPLICATION
]
]
[
ROWGUIDCOL
]
[
[
...n
]
]
::=
[
type_schema_name
.
]
type_name
[
(
precision
[
,
scale
]
|
max
|
[
{
CONTENT
|
DOCUMENT
}
]
xml_schema_collection
)
]
::=
[
CONSTRAINT
constraint_name
]
{
{
PRIMARY
KEY
|
UNIQUE
}
[
CLUSTERED
|
NONCLUSTERED
]
[
WITH
FILLFACTOR
=
fillfactor
|
WITH
(
<
index_option
>
[
,
...n
]
)
]
[
ON
{
partition_scheme_name
(
partition_column_name
)
|
filegroup
|
"default"
}
]
|
[
FOREIGN
KEY
]
REFERENCES
[
schema_name
.
]
referenced_table_name
[
(
ref_column
)
]
[
ON
DELETE
{
NO
ACTION
|
CASCADE
|
SET
NULL
|
SET
DEFAULT
}
]
[
ON
UPDATE
{
NO
ACTION
|
CASCADE
|
SET
NULL
|
SET
DEFAULT
}
]
[
NOT
FOR
REPLICATION
]
|
CHECK
[
NOT
FOR
REPLICATION
]
(
logical_expression
)
}
::=
column_name
AS
computed_column_expression
[
PERSISTED
[
NOT
NULL
]
]
[
[
CONSTRAINT
constraint_name
]
{
PRIMARY
KEY
|
UNIQUE
}
[
CLUSTERED
|
NONCLUSTERED
]
[
WITH
FILLFACTOR
=
fillfactor
|
WITH
(
[
,
...n
]
)
]
|
[
FOREIGN
KEY
]
REFERENCES
referenced_table_name
[
(
ref_column
)
]
[
ON
DELETE
{
NO
ACTION
|
CASCADE
}
]
[
ON
UPDATE
{
NO
ACTION
}
]
[
NOT
FOR
REPLICATION
]
|
CHECK
[
NOT
FOR
REPLICATION
]
(
logical_expression
)
[
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
(
[
,
...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
]
|
CHECK
[
NOT
FOR
REPLICATION
]
(
logical_expression
)
}
::=
{
PAD_INDEX
=
{
ON
|
OFF
}
|
FILLFACTOR
=
fillfactor
|
IGNORE_DUP_KEY
=
{
ON
|
OFF
}
|
STATISTICS_NORECOMPUTE
=
{
ON
|
OFF
}
|
ALLOW_ROW_LOCKS
=
{
ON
|
OFF}
|
ALLOW_PAGE_LOCKS
={
ON
|
OFF}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |