简体   繁体   English

在SQL Server Express中创建表

[英]Creating a table in SQL Server Express

I'm trying to setup a SQL database for a local program management and install system. 我正在尝试为本地程序管理和安装系统设置SQL数据库。 I think i've created a basic serviceable schema that should work, but i'm unsure how to translate it to a CREATE TABLE command. 我想我已经创建了一个应该可行的基本可维护模式,但我不确定如何将其转换为CREATE TABLE命令。 Can someone help me with the translation and/or point me to resources that will? 有人可以帮我翻译和/或指向我的资源吗?

Schema: 架构:

Programs(
    progID[key] (integer/index field?),
    name (text),
    desc (text), 
    iconFile (path to file),
    installScript (path to file))

Use the following syntax: 使用以下语法:

create table programs (
    progid int primary key identity(1,1),
    name nvarchar(255),
    description nvarchar(500),
    iconFile nvarchar(255),
    installScript nvarchar(255)
)

The primary key sets the progid column to be the index column of the table. primary keyprogid列设置为表的索引列。 The identity(1,1) clause sets the progid to be an auto-incrementing field, starting at 1 and incrementing by 1 each time. identity(1,1)子句将progid设置为自动递增字段,从1开始并每次递增1。 Therefore, the following SQL enters the corresponding rows into programs : 因此,以下SQL将相应的行输入到programs

insert into (name, description, iconfile, installscript)
values ('Name1', 'Test test', 'C:\file\path', 'C:\script\path')
insert into (name, description, iconfile, installscript)
values ('Name2', 'Test 123', 'C:\file\path1', 'C:\script\path2')

------------------------------------------------------------------
progid    name     description    iconfile        installscript
------------------------------------------------------------------
1         Name1    Test test      C:\file\path    C:\script\path
2         Name2    Test 123       C:\file\path1   C:\script\path2

Notice, also, that I used nvarchar instead of varchar . 另请注意,我使用的是nvarchar而不是varchar This is because nvarchar uses the Unicode character set, while varchar uses the ASCII character set. 这是因为nvarchar使用Unicode字符集,而varchar使用ASCII字符集。 nvarchar is the recommended usage, since ASCII characters take no additional space in Unicode, but Unicode does allow for internationalization and obscure characters. nvarchar是推荐用法,因为Unicode字符在Unicode中不占用额外空间,但Unicode允许国际化和模糊字符。

Questions regarding SQL syntax should be directed over at Stack Overflow . 有关SQL语法的问题应该在Stack Overflow上进行

That said, if you have SQL Studio Management Express ( grab it from here ), when you create your table structure, but before saving it, you can click on the "Generate Script" icon (it has a scroll with a disk on it), and it will show you the code it's about to execute. 也就是说,如果您有SQL Studio Management Express( 从这里获取 ),当您创建表结构时,但在保存之前,您可以单击“生成脚本”图标(它上面有一个带有磁盘的滚动) ,它将显示它即将执行的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM