注册 登录
编程论坛 SQL Server论坛

帮忙看看什么地方错了 老纠结了

zxd543 发布于 2012-11-13 12:22, 584 次点击
DROP DATABASE IF EXISTS `ScoreManage`;   
CREATE DATABASE `ScoreManage`DEFAULT CHARACTER SET utf8;
USE `ScoreManage`;
create table course(
cid int(11)  not null,
cname varchar(40) not null,
coursehours int(3)  not null,
primary keyPK_course(cid)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

create table student(
    sid int(11) not null,
    sname varchar(40) not null,
password varchar(40) not null,
    primary keyPK_student (sid)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

create table score(
    cid int not null,
    sid int not null,
    score int,
    foreign key(sid) references student(sid),
foreign key(cid) references course (cid),
primary keyPK_score(cid,sid)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;


CREATE  TABLE  admin (
admin_name  VARCHAR(40) NOT NULL ,
admin_password VARCHAR(40) NOT NULL ,
  PRIMARY KEY  admin(admin_name)
)ENGINE = InnoDBDEFAULT CHARSET=utf8;
5 回复
#2
zxd5432012-11-13 12:28
好长时间没写SQL语句了
写了一个以后发现错误解决不了
希望大神帮忙呀!!
SQL 查询:

CREATE TABLE course(

cid int( 11 ) NOT NULL ,
cname varchar( 40 ) NOT NULL ,
coursehours int( 3 ) NOT NULL ,
PRIMARY keyPK_course( cid )
) ENGINE = InnoDB DEFAULT CHARSET = utf8

MySQL 返回:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'keyPK_course(cid)
)ENGINE=InnoDB DEFAULT CHARSET=utf8' at line 5

解决这一个错误就好

[ 本帖最后由 zxd543 于 2012-11-13 12:30 编辑 ]
#3
半杯清茶2012-11-13 14:19
CREATE TABLE course(
cid int( 11 ) NOT NULL ,
cname varchar( 40 )  COLLATE Chinese_PRC_CI_AS  NOT NULL ,
coursehours int( 3 ) NOT NULL,
constraint  keyPK_course PRIMARY  key ( cid )  
)
#4
半杯清茶2012-11-13 14:31
CREATE TABLE course(
cid int( 11 ) NOT NULL ,
cname varchar( 40 )  COLLATE Chinese_PRC_CI_AS  NOT NULL ,
coursehours int( 3 ) NOT NULL,
constraint  keyPK_course PRIMARY  key ( cid )  
)
#5
zxd5432012-11-13 20:34
回复 4楼 半杯清茶
CREATE TABLE course(

cid int( 11 ) NOT NULL ,
cname varchar( 40 ) NOT NULL ,
coursehours int( 3 ) NOT NULL ,
PRIMARY keyPK_course( cid ) //PRIMARY key PK_course( cid ) 这样就可以了 有点蒙
) ENGINE = InnoDB DEFAULT CHARSET = utf8

貌似你那样写也是可以的
#6
半杯清茶2012-11-20 10:26
我哪个写法是sql server   你的写法应该是mysql
1