create table Votes
(
VoteID int identity(1,1) primary key not null,
Item varchar(20) not null,
VoteCount int not null,
)
go---VoteID的值总是从2开始自增,怎么使初始值改为1啊???

解决方案 »

  1.   

    create table Votes 

    VoteID int identity(0,1) primary key not null, 
    Item varchar(20) not null, 
    VoteCount int not null, 
      

  2.   

    先去掉子增列,在加上去--去掉该子增列
    alter table Votes  drop column VoteID 
    --添加一个子增列
    alter table Votes  add VoteID int identity(1,1) primary key
      

  3.   

    --你的表没问题的,应该从1开始。
    create table Votes 

    VoteID int identity(1,1) primary key not null, 
    Item varchar(20) not null, 
    VoteCount int not null, 

    go insert Votes (Item,VoteCount) select 'aaaaa',100
    insert Votes (Item,VoteCount) select 'bbbbb',200
    select * from Votes
    go 
    drop table Votes/*
    VoteID      Item                 VoteCount   
    ----------- -------------------- ----------- 
    1           aaaaa                100
    2           bbbbb                200(所影响的行数为 2 行)
    */
      

  4.   

    Truncate是SQL中的一个删除数据表内容的语句,用法是: 
      语法 
      TRUNCATE TABLE name 
      参数 
      name 
      是要截断的表的名称或要删除其全部行的表的名称。 
      下面是对Truncate语句在MSSQLServer2000中用法和原理的说明: 
      Truncate table 表名 速度快,而且效率高,因为: 
      TRUNCATE TABLE 在功能上与不带 WHERE 子句的 DELETE 语句相同:二者均删除表中的全部行。但 TRUNCATE TABLE 比 DELETE 速度快,且使用的系统和事务日志资源少。 
      DELETE 语句每次删除一行,并在事务日志中为所删除的每行记录一项。TRUNCATE TABLE 通过释放存储表数据所用的数据页来删除数据,并且只在事务日志中记录页的释放。 
      TRUNCATE TABLE 删除表中的所有行,但表结构及其列、约束、索引等保持不变。新行标识所用的计数值重置为该列的种子。如果想保留标识计数值,请改用 DELETE。如果要删除表定义及其数据,请使用 DROP TABLE 语句。 
      对于由 FOREIGN KEY 约束引用的表,不能使用 TRUNCATE TABLE,而应使用不带 WHERE 子句的 DELETE 语句。由于 TRUNCATE TABLE 不记录在日志中,所以它不能激活触发器。 
      TRUNCATE TABLE 不能用于参与了索引视图的表。 
      对用TRUNCATE TABLE删除数据的表上增加数据时,要使用UPDATE STATISTICS来维护索引信息。 
      如果有ROLLBACK语句,DELETE操作将被撤销,但TRUNCATE不会撤销。 
      示例 
      下例删除 authors 表中的所有数据。 
      TRUNCATE TABLE authors 
      权限 
      TRUNCATE TABLE 权限默认授予表所有者、sysadmin 固定服务器角色成员、db_owner 和 db_ddladmin 固定数据库角色成员且不可转让。 
      补充参数: 
      TRUNCATE TABLE name [DROP/REUSE STORAGE] 
      DROP STORAGE:显式指明释放数据表和索引的空间 
      REUSE STORAGE:显式指明不释放数据表和索引的空间
      

  5.   

    create table Votes 

    VoteID int identity(1,1) primary key not null, -- 这里不需要not null 吧?
    Item varchar(20) not null, 
    VoteCount int not null, 

    go 
      

  6.   

    select * into # from Votes 
    truncate table Votes 
    insert Votes select ... from #
    drop table #
      

  7.   

    终于解决了,谢谢!
    我使用truncate语句删的内容,那这是不是意味着在创建表的时候会有一个隐藏数据占用了一行呢?但又好像是讲不通的(在其他表中就没有这种情况),不管怎么样还是谢谢大家的关注与解答
      

  8.   

    1,关闭防火墙 
    2,如果操作系统是XP,则安装SQL2000SP4 
    3,在控制面板中手工配制ODBC
      

  9.   

    1,关闭防火墙 
    2,如果操作系统是XP,则安装SQL2000SP4 
    3,在控制面板中手工配制ODBC