create table type 
(
Type_ID int primary key NOT NULL   AUTO_INCREMENT,
TypeName varchar(25) not null
)
ENGINE=INNODB AUTO_INCREMENT=1;我想把 Type_ID 列设为主键,并且是自动增长列,
从网上搜了一下,大概是这样,可运行出错,不知道是什么问题了
大家帮忙解决下啦

解决方案 »

  1.   


    create   table   type   

    Type_ID int identity(1,1) primary   key   NOT   NULL , 
    TypeName varchar(25) not   null 

      

  2.   

    加上  identity(1,1)     运行就报错啊
      

  3.   

    create table type   

      Type_ID int identity(1,1) primary key   NOT NULL , 
      TypeName varchar(25) NOT NULL
      

  4.   


    create   table   typedddd   

    Type_ID int(3)  AUTO_INCREMENT NOT   NULL primary   key, 
    TypeName varchar(25) 

      

  5.   

    不用手动的,
    create   table   type      
    (  
        Type_ID   int   identity(1,1)   primary   key       NOT   NULL   ,  
        TypeName   varchar(25)   NOT   NULL
    )你只要输入TYPENAME的数据就行了
    ID会自动增长
      

  6.   


    create table desttable
    (
       Type_ID int identity(1,1) primary key not null,
       TypeName varchar(25)
    )
    identity 的语法是,第一个参数为自增量初始值,第2个参数是自增步长,如果想从10开始,每次增长2的话,那么identity的形式就要是identity(10,2)
      

  7.   


    insert into type values('0','AAAA')
    insert into type values('0','BBBB')
      

  8.   


    Type_ID TypeName 
    1 AAAA
    2 BBBB
      

  9.   

    可以了,我太高兴了,终于解决一个问题了,真是太感谢你了。我想说一句  identity  是sql里的用法,用在我这行不通,不过还是谢谢了
      

  10.   

    我还有问题 ^_^
    ALTER  TABLE  type  AUTO_INCREMENT  =  1ENGINE=INNODB AUTO_INCREMENT=1;这两句话什么意思呀?
    恩,fwacky 你是怎么这么快知道 insert into type values('0','AAAA') 这么写的?
      

  11.   

    楼上各位,有没搞错啊!
    楼主说的是MYSQL,不是MSSQL。
      

  12.   

    对呀,是 mysql ,我以前不用mysql,但是这次不得不用,现学啊,真费劲,急死我了!
    大家快帮帮我啦 ^_^
      

  13.   


    ALTER     TABLE     type     AUTO_INCREMENT     =     3这是,修改它的初始值 
      

  14.   

    原理 和 mssql  都一样!
      

  15.   


    create table product
    (
        Pro_ID       int             AUTO_INCREMENT   primary key,
            Pro_Name       varchar(25)        not null,
            Pro_TypeID        int                  not null,
            Pro_Sample       varchar(100)        not null,
            Pro_price         DECIMAL              not null,
            Pro_curt       varchar(300)        not null,
            Pro_Time       datetime           not null
    )
    ALTER TABLE product ADD CONSTRAINT fk_Pro_TypeID FOREIGN KEY (Pro_TypeID) REFERENCES type(Type_ID) ON UPDATE CASCADE ; 
    我想一快运行,可就是不行,没次都要先键完表,在添加约束在 mssql 里 加个 go 就可以了,这个怎么弄呀?
      

  16.   


    create   table   product 

            Pro_ID             int                         AUTO_INCREMENT       primary   key, 
                    Pro_Name             varchar(25)               not   null, 
                    Pro_TypeID                 int                                     not   null, 
                    Pro_Sample             varchar(100)               not   null, 
                    Pro_price                   DECIMAL                             not   null, 
                    Pro_curt             varchar(300)               not   null, 
                    Pro_Time             datetime                     not   null 
    ALTER   TABLE   product   ADD   CONSTRAINT   fk_Pro_TypeID   FOREIGN   KEY   (Pro_TypeID)   REFERENCES   type(Type_ID)   ON   UPDATE   CASCADE   ;   
      

  17.   

    create   table   product 

            Pro_ID             int                         AUTO_INCREMENT       primary   key, 
                    Pro_Name             varchar(25)               not   null, 
                    Pro_TypeID                 int                                     not   null, 
                    Pro_Sample             varchar(100)               not   null, 
                    Pro_price                   DECIMAL                             not   null, 
                    Pro_curt             varchar(300)               not   null, 
                    Pro_Time             datetime                     not   null 
    ALTER   TABLE   product   ADD   CONSTRAINT   fk_Pro_TypeID   FOREIGN   KEY   (Pro_TypeID)   REFERENCES   type(Type_ID)   ON   UPDATE   CASCADE   ;   
      

  18.   

    我刚才这么做了,没有运行成功,原因是我在  ALTER   TABLE   product     .... 前加了一个注释,
    如果我那需要一个注释,而且还想批量运行怎么弄?
      

  19.   


    create   table   product 

            Pro_ID             int                         AUTO_INCREMENT       primary   key, 
                    Pro_Name             varchar(25)               not   null, 
                    Pro_TypeID                 int                                     not   null, 
                    Pro_Sample             varchar(100)               not   null, 
                    Pro_price                   DECIMAL                             not   null, 
                    Pro_curt             varchar(300)               not   null, 
                    Pro_Time             datetime                     not   null 
    ) ;/**dddddddddddddddddddddddddd*/ALTER   TABLE   product   ADD   CONSTRAINT   fk_Pro_TypeID   FOREIGN   KEY   (Pro_TypeID)   REFERENCES   type(Type_ID)   ON   UPDATE   CASCADE   ;  
      

  20.   

    java 连 mysql  除了导 sql 包,还导什么包?
      

  21.   


    create   table   product 

            Pro_ID             int                         AUTO_INCREMENT       primary   key, 
                    Pro_Name             varchar(25)               not   null, 
                    Pro_TypeID                 int                                     not   null, 
                    Pro_Sample             varchar(100)               not   null, 
                    Pro_price                   DECIMAL                             not   null, 
                    Pro_curt             varchar(300)               not   null, 
                    Pro_Time             datetime                     not   null 
    ) ;# dddddddddddddddddddddALTER   TABLE   product   ADD   CONSTRAINT   fk_Pro_TypeID   FOREIGN   KEY   (Pro_TypeID)   REFERENCES   type(Type_ID)   ON   UPDATE   CASCADE   ;   
      

  22.   

    java   连   mysql     除了导   sql   包,还导什么包?
    =====================================================
    这个我就不会了!
    我学的是,Visual C# .net 
      

  23.   

    我好笨啊, -_-
    找不到  java   连   mysql 的 mysql连接驱动呀!
      

  24.   

    MYsql下:create table atest
    (
    col1 int not null auto_increment,
    primary key(col1),
    col2 varchar(2)
    );
      

  25.   

     C#  我也会 ^_^嘿嘿  一点点 至今 那简单的三层还有点不明白呢
    做练习啦,给自己考试,因为mysql我不会,所以考试加学习咯
      

  26.   

    create table atest
    (
    col1 int not null auto_increment,
    primary key(col1),
    col2 varchar(2)
    );
      

  27.   

    对了,你是学.net 那我以后学的时候就可以向你请教咯!^_^
      

  28.   

    是说用java连接mysql吗??,需要下载个驱动包mysql-connector-java-3.2.0-alpha-bin.jar,不知道你是用什么工具连mysql啊?
      

  29.   

    create table type 

    Type_ID int  AUTO_INCREMENT primary key, 
    TypeName varchar(25) not null 

      

  30.   

    AUTO_INCREMENT   这个是MYSQL设置自动增长列的函数
    IDENTITY         这个是SQLSERVER中设置自动增长列的函数
      

  31.   

    create table type 

    Type_ID int AUTO_INCREMENT primary key, 
    TypeName varchar(25) not null 
    ) 如果是主键的话不用设置not null
    MYSQL中的自动增长默认是从1开始的