使用drop命令和create命令的SQL错误

时间:2019-04-07 14:10:05

标签: sql

我必须为数据库项目创建一个表,但是我不断遇到两个错误。对于放置代码,我返回一个错误,指出未正确结束的sql命令。对于create table命令,我一直返回缺少或无效的选项。

drop table Histology Tissue cascade constraints;

create table Histology Tissue
(
HistologyID     VARCHAR (15) PRIMARY KEY, 
Tissue Type     Char (25) NOT NULL,
Date Received   Date,
DonorID         VARCHAR (15) NOT NULL,
Species         Char (20) NOT NULL, 
Disease type    Char (20) NOT NULL, 
AnimalID        Numeric (15),
constraint PKhistology_tissue primary key (HistologyID),
constraint FKDonorID foreign key (DonorID) references External Sample,
constraint FKAnimalID foreign key (AnimalID references Internal Sample
);

describe Histology Tissue;

1 个答案:

答案 0 :(得分:0)

对于外键,请指定参考表的表名和列名及其主键。

DROP TABLE [histology tissue]  

CREATE TABLE [histology tissue]
 ( histologyid varchar (15) PRIMARY KEY, 
   [tissue type] char (25) NOT NULL, 
   [date received] date, 
   donorid varchar (15) NOT NULL FOREIGN KEY REFERENCES tablename(donorid), 
   species char (20) NOT NULL, 
   [disease type] char (20) NOT NULL, 
   animalid numeric (15)FOREIGN KEY REFERENCES tablename(donorid), 
    )