Home > Database > Mysql Tutorial > sqlserver2005自动创建数据表和自动添加某个字段索引

sqlserver2005自动创建数据表和自动添加某个字段索引

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 18:06:29
Original
1211 people have browsed it

C#编程程序的时候,让程序自动创建数据表,然后给数据表添加索引,这个方法是在百度百科找到,我自已只是简单的修改了一下

创建数据表的SQL语句如下:

string tatlename = "T_useruid";//定义一个变量。用于自动创建数据表的名称,当前表名为:T_useruid

string sql = "CREATE TABLE [dbo].[" + tatlename + "]([Cid] [int] IDENTITY(1,1) NOT NULL,[Uid] [nchar](32) COLLATE Chinese_PRC_CI_AS NULL,CONSTRAINT [PK_" + tatlename + "] PRIMARY KEY CLUSTERED ([Cid] ASC)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]) ON [PRIMARY]";



给这个数据表:T_useruid 的Uid字段增加一个索引

string sql = "CREATE UNIQUE INDEX PK_T_useruid_u ON T_useruid (Uid)";

分析SQL:CREATE UNIQUE INDEX 索引名称 ON 数据表名称 (字段名称)
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template