2 wei guanghui Wei_Guanghui 于 2014.12.04 16:59 提问

这个sql语句什么意思?

CREATE TABLE [dbo].users NOT NULL,
[hashed_password] varchar NOT NULL,
[salt] varchar NOT NULL,
[lv] [smallint] NOT NULL,
[created_on] [datetime] NOT NULL DEFAULT(GETDATE()),
[created_platform] [smallint] NOT NULL,
[created_ip] varchar NOT NULL,
[last_login_on] [datetime] NULL,
[last_login_platform] [smallint] NULL,
[last_login_ip] varchar NULL,
[login_on] [datetime] NULL,
[login_platform] [smallint] NULL,
[login_ip] varchar NULL,
[status] [tinyint] NOT NULL,
CONSTRAINT [PK_users] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

CONSTRAINT [PK_users] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
这些不是很明白啊

8个回答

caozhy
caozhy   Ds   Rxr 2014.12.04 17:09

CREATE TABLE 创建了一个表,PK_users这里定义了一个主键,并且设置了排序规则和建立了索引。

Wei_Guanghui
Wei_Guanghui 后面的能解释具体点么?从CONSTRAINT开始解释下,谢谢
接近 3 年之前 回复
caozhy
caozhy   Ds   Rxr 2014.12.04 17:11

从字面上看
CREATE TABLE [dbo].users NOT NULL, 用户表
[hashed_password] varchar NOT NULL, 密码的Hash
[salt] varchar NOT NULL, Hash的Salt
[lv] [smallint] NOT NULL, 等级
[created_on] [datetime] NOT NULL DEFAULT(GETDATE()), 创建时间
[created_platform] [smallint] NOT NULL, 创建的平台
[created_ip] varchar NOT NULL, 创建的ip
[last_login_on] [datetime] NULL, 上次登录时间
[last_login_platform] [smallint] NULL, 上次登录平台
[last_login_ip] varchar NULL, 上次登录ip
[login_on] [datetime] NULL, 登录时间
[login_platform] [smallint] NULL, 登录平台
[login_ip] varchar NULL, 登录ip
[status] [tinyint] NOT NULL, 状态

q107770540
q107770540   Ds   Rxr 2014.12.04 17:51

这其实就是个创建数据库表的语句

Wei_Guanghui
Wei_Guanghui   2014.12.05 10:09

CONSTRAINT [PK_users] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
字段我知道,就是这些不是很懂,第一次接触啊

fredrickhu
fredrickhu   Ds   Rxr 2014.12.05 11:10

这个你直接去查联机丛书比较好。如果你运行的SSMS,直接按F1出来的帮助就可以了。你可以直接搜索不懂的部分。

fredrickhu
fredrickhu   Ds   Rxr 2014.12.05 11:16

ON [PRIMARY] 表示这个表建立在 PRIMARY主数据组

PAD_INDEX = OFF,
STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, 允许行锁
ALLOW_PAGE_LOCKS = ON 允许页锁

具体的介绍在这里

fredrickhu
fredrickhu   Ds   Rxr 2014.12.05 11:16
eagleyan
eagleyan   Rxr 2014.12.06 15:18

DML = Data Manipulation Language
DDL = Data Definition Language
猜猜这个是哪个?

Csdn user default icon
上传中...
上传图片
插入图片