I have an issue with SQL statement - sql

Create Table Person (
ID integer primary key
, [name] character(15) not null
, address character(15)
, phone integer
);
Create Table Surveyor (
surveyID integer
, certificationDate Datetime
, ID integer
, primary KEY (surveyID,ID)
, FOREIGN KEY (ID) REFERENCES Person
);
Create Table Points (
PntID integer primary key
, N float not null
, E float not null
, Height float not null
);
Create Table Polygon (
polyID integer primary key
, area float not null
, atleastonepoint integer not null
, foreign key (atleastonepoint) references Points(PntID)
, check (area > 0)
);
Create Table Block (
blockID integer
, blockName character (15) not null
, polyID integer
, polyLength float not null
, primary KEY (blockID,polyID)
, onemunicipalAuthority character (15) not null
, foreign key (polyID) references polygon
, check (polyLength > 0)
);
Create Table Parcel (
parcelname character (15)
, blockID integer
, polyID integer
, primary KEY (parcelname,blockID,polyID)
, foreign key (polyID) references polygon
, foreign key (blockID) REFERENCES block
);
ERROR : Relationship must be on the same number of fields with the same data types, when I try to implement the last one , CREATE => Parcel
thanx in advance

Try this command:
Create Table Parcel (
parcelname character (15)
, blockID integer
, polyID integer
, primary KEY (parcelname,blockID,polyID)
, foreign key (polyID) references polygon
, foreign key (blockID,polyID) REFERENCES block
);

Related

SQL integrity constraints primary and foreign keys

I am following some examples and the following should work, but I am getting some errors. Can someone tell me what is wrong?
/* Data Definition */
CREATE TABLE CUSTOMERS
(CUST_NO INTEGER ,
CUST_NAME VARCHAR(40) ,
STREET VARCHAR(40) ,
TOWN VARCHAR(40) ,
POSTCODE INTEGER ,
CR_LIMIT INTEGER ,
CURR_BALANCE INTEGER ,
PRIMARY KEY (CUST_NO)
);
CREATE TABLE PRODUCTS
(PROD_COD VARCHAR(10) ,
DESCRIPTION VARCHAR(50) ,
PROD_GROUP CHAR(1) ,
LIST_PRICE INTEGER ,
QTY_ON_HAND INTEGER ,
REMAKE_LEVEL INTEGER ,
REMAKE_QTY INTEGER ,
PRIMARY KEY (PROD_COD)
);
CREATE TABLE ORDERS
(ORDER_NO INTEGER ,
ORDER_DATE DATE ,
CUST_NO INTEGER ,
PRIMARY KEY (ORDER_NO),
FOREIGN KEY (CUST_NO) REFERENCES CUSTOMERS(CUST_NO)
);
CREATE TABLE ORDER_DETAILS
(ORDER_NO INTEGER ,
PROD_COD VARCHAR(10) ,
ORDER_QTY INTEGER ,
ORDER_PRICE INTEGER ,
PRIMARY KEY (ORDER_NO, PROD_COD),
FOREIGN KEY (ORDER_NO) REFERENCES ORDERS(ORDER_NO),
FOREIGN KEY (PROD_COD) REFERENCES PRODUCTS(PROD_COD)
);
And I am getting these errors when I try to insert values in to the tables:
I can't work it out as it seems that I am referencing the right things, but obviously I am not.
Is it because of the composite primary key? That seemed to work in the example.
I am using Oracle SQL Developer 4.
It would seem you are trying to insert an order for a customer that does not exist. Is there a row in customers with cust_no = 13144 ?

How to make (patient id) forgein key in table of bill?

I try to create three tables by using website suport compiler any code but I have a problem in the table of the bill.
When I run it I get to error show me it is near in foreign key
These are codes of three tables
CREATE TABLE patient (
Patient Id (5) Primary key,
Name Varchar (20) Not null ,
Age Int Not null ,
Weight Int Not null ,
Gender Varchar (10) Not null,
Address Varchar (50) Not null ,
Disease Varchar (20) Not null
);
CREATE TABLE doctors (
DoctorId Varchar (5) Primary key,
Doctorname Varchar (15) Not null,
Dept Varchar (15) Not null
);
CREATE TABLE bill (
Bill_no Varchar (50) Primary key,
Patient_Id Varchar (5) Foreign key,,
doctor_charge Int Not null,
patient_type Varchar (10) null,
no_of_days Int null,
lab_charge Int null,
bill Int Not null
);
Patient Table
CREATE TABLE patient
(
patient_id VARCHAR (5) PRIMARY KEY,
name VARCHAR (20) NOT NULL,
age INT NOT NULL,
weight INT NOT NULL,
gender VARCHAR (10) NOT NULL,
address VARCHAR (50) NOT NULL,
disease VARCHAR (20) NOT NULL
);
Errors
No data type has been assigned in Patient id column (Patient Id (5)
Primary key)
Patient id column name contains spaces. You need to
enclose the column name in double quotes or replace space with something else
(ex: _). It's not recommended to use spaces.
A column name with space
CREATE TABLE tablename ("column name" datatype);
Doctors Table
CREATE TABLE doctors
(
doctorid VARCHAR (5) PRIMARY KEY,
doctorname VARCHAR (15) NOT NULL,
dept VARCHAR (15) NOT NULL
);
Bill Table
CREATE TABLE bill
(
bill_no VARCHAR (50) PRIMARY KEY,
patient_id VARCHAR (5),
doctor_charge INT NOT NULL,
patient_type VARCHAR (10) NULL,
no_of_days INT NULL,
lab_charge INT NULL,
bill INT NOT NULL,
FOREIGN KEY (patient_id) REFERENCES patient(patient_id)
);
Errors
The way you have assigned foreign key is wrong. Please refer this and this article for more information. (Patient_Id Varchar (5) Foreign key,,)
There are two commans in the Patient_Id column (Patient_Id Varchar (5) Foreign key,,)
You have to provide reference of the table for which you want to use the reference key.
For example, you have table Persons which has Primary key PersonID, in that case if you want to use that as foreign key in another table, lets say Orders.
In Oracle
CREATE TABLE Orders (
OrderID numeric(10) not null,
OrderNumber numeric(10) not null,
PersonID numeric(10) not null,
CONSTRAINT fk_person_id
FOREIGN KEY (PersonID )
REFERENCES Persons(PersonID )
Your Case :
CREATE TABLE bill
( Bill_no Varchar (50) Primary key,
Patient_Id Varchar (5),
doctor_charge Int Not null,
patient_type Varchar (10) null,
no_of_days Int null,
lab_charge Int null,
bill Int Not null,
CONSTRAINT fk_patient_id
FOREIGN KEY (Patient_Id)
REFERENCES patient(Patient_Id)
);
Remove the 'Foreign Key' from the table creation script.
Add this to your SQL script:
ALTER TABLE [Bill] WITH CHECK ADD CONSTRAINT [FK_Bill_Patient] FOREIGN KEY([Patient_Id])
REFERENCES [Patient] ([Patient_Id])
GO
ALTER TABLE [Bill] CHECK CONSTRAINT [FK_Bill_Patient]
GO
The words FOREIGN KEY are only needed for introducing the name of the FK constraint. Since your other constraints are not named, you might as well skip that part and go straight to REFERENCES.
If you specify a foreign key constraint as part of the column definition, you can omit the datatype to allow it to inherit from its parent at the time of creation, which I think is good practice as the types will automatically match.
We use VARCHAR2 in Oracle, not VARCHAR.
You don't need to specify NULL for columns that are allowed to be null.
I am not sure a 5-character string is a good datatype for a unique ID. How will you generate the values? Normally an auto-incrementing sequence number simplifies this.
create table doctors
( doctorid varchar2(5) primary key
, doctorname varchar2(15) not null
, dept varchar2(15) not null );
create table patients
( patient_id varchar2(5) primary key
, name varchar2(20) not null
, age integer not null
, weight integer not null
, gender varchar2(10) not null
, address varchar2(50) not null
, disease varchar2(20) not null );
create table bills
( bill_no varchar2(50) primary key
, patient_id references patients -- Allow datatype to inherit from parent
, patient_type varchar2(10)
, no_of_days integer
, lab_charge integer
, bill integer not null );

I'm trying to figure out the order my drop tables and create tables should be in if someone can help me out

I can't figure out the order my drop tables and create tables should be in. I'm creating a knockoff soccer registration database. Originally I was fine but wanted to make it more complex and since then I can't figure out the order everything is supposed to be in. I know this sounds dumb, but I'm still a student who is trying to create something on his own to learn more. Below is the order my drop tables and create tables are in right now along with my alter tables. I greatly appreciate your guys help!
-- --------------------------------------------------------------------------------
-- Drop Tables
-- --------------------------------------------------------------------------------
IF OBJECT_ID('TTeamPlayers') IS NOT NULL DROP TABLE TTeamPlayers
IF OBJECT_ID('TPlayers') IS NOT NULL DROP TABLE TPlayers
IF OBJECT_ID('TTeamCoaches') IS NOT NULL DROP TABLE TTeamCoaches
IF OBJECT_ID('TFields') IS NOT NULL DROP TABLE TFields
IF OBJECT_ID('TAgeGroups') IS NOT NULL DROP TABLE TAgeGroups
IF OBJECT_ID('TReferees') IS NOT NULL DROP TABLE TReferees
IF OBJECT_ID('TCoaches') IS NOT NULL DROP TABLE TCoaches
IF OBJECT_ID('TStates') IS NOT NULL DROP TABLE TStates
IF OBJECT_ID('TSockSizes') IS NOT NULL DROP TABLE TSockSizes
IF OBJECT_ID('TPantSizes') IS NOT NULL DROP TABLE TPantSizes
IF OBJECT_ID('TShirtSizes') IS NOT NULL DROP TABLE TShirtSizes
IF OBJECT_ID('TGenders') IS NOT NULL DROP TABLE TGenders
IF OBJECT_ID('TTeams') IS NOT NULL DROP TABLE TTeams
IF OBJECT_ID('Z_TeamPlayers') IS NOT NULL DROP TABLE Z_TeamPlayers
IF OBJECT_ID('Z_TeamCoaches') IS NOT NULL DROP TABLE Z_TeamCoaches
IF OBJECT_ID('Z_Teams') IS NOT NULL DROP TABLE Z_Teams
IF OBJECT_ID('Z_Players') IS NOT NULL DROP TABLE Z_Players
IF OBJECT_ID('Z_Coaches') IS NOT NULL DROP TABLE Z_Coaches
IF OBJECT_ID('TUsers') IS NOT NULL DROP TABLE TUsers
IF OBJECT_ID('TRoles') IS NOT NULL DROP TABLE TRoles
IF OBJECT_ID('TLogins') IS NOT NULL DROP TABLE TLogins
IF OBJECT_ID('TFieldGames') IS NOT NULL DROP TABLE TFieldGames
------------------------------------------------------------------------------------
-- create tables
------------------------------------------------------------------------------------
create table TTeams
(
intTeamID INTEGER NOT NULL
,strTeam VARCHAR(50) NOT NULL
,CONSTRAINT TTeams_PK PRIMARY KEY ( intTeamID )
)
CREATE TABLE TGenders
(
intGenderID INTEGER NOT NULL
,strGender VARCHAR(10) NOT NULL
,CONSTRAINT TGenders_PK PRIMARY KEY ( intGenderID )
)
CREATE TABLE TShirtSizes
(
intShirtSizeID INTEGER NOT NULL
,strShirtSize VARCHAR(50) NOT NULL
,CONSTRAINT TShirtSizes_PK PRIMARY KEY ( intShirtSizeID )
)
CREATE TABLE TPantSizes
(
intPantSizeID INTEGER NOT NULL
,strPantSize VARCHAR(50) NOT NULL
,CONSTRAINT TPantSizes_PK PRIMARY KEY ( intPantSizeID )
)
CREATE TABLE TSockSizes
(
intSockSizeID INTEGER NOT NULL
,strSockSize VARCHAR(50) NOT NULL
,CONSTRAINT TSockSizes_PK PRIMARY KEY ( intSockSizeID )
)
CREATE TABLE TStates
(
intStateID INTEGER NOT NULL
,strState VARCHAR(50) NOT NULL
,CONSTRAINT TStates_PK PRIMARY KEY ( intStateID )
)
CREATE TABLE TReferees
(
intRefereeID INTEGER NOT NULL
,strFirstName VARCHAR(50) NOT NULL
,strMiddleName VARCHAR(50) NOT NULL
,strLastName VARCHAR(50) NOT NULL
,strEmail VARCHAR(50) NOT NULL
,dtmDateOfBirth DATE NOT NULL
,strCity VARCHAR(50) NOT NULL
,intStateID INTEGER NOT NULL
,strAddress varchar(50) not null
,strZip varchar(50) not null
,strPhoneNumber VARCHAR(50) NOT NULL
,CONSTRAINT TReferees_PK PRIMARY KEY ( intRefereeID )
)
CREATE TABLE TAgeGroups
(
intAgeGroupID INTEGER NOT NULL
,strAge VARCHAR(10) NOT NULL
,CONSTRAINT TAgeGroups_PK PRIMARY KEY ( intAgeGroupID )
)
CREATE TABLE TFields
(
intFieldID INTEGER NOT NULL
,strFieldName VARCHAR(50) NOT NULL
,CONSTRAINT TFields_PK PRIMARY KEY ( intFieldID )
)
CREATE TABLE TCoaches
(
intCoachID INTEGER NOT NULL
,strFirstName VARCHAR(50) NOT NULL
,strMiddleName varchar(50) not null
,strLastName VARCHAR(50) NOT NULL
,intShirtID INTEGER NOT NULL
,dtmDateOfBirth DATE NOT NULL
,strCity Varchar(50) not null
,intStateID integer not null
,strPhoneNumber varchar(50) not null
,strEmail VARCHAR(50) NOT NULL
,strAddress varchar(50) not null
,strZip varchar(50) not null
,CONSTRAINT TCoaches_PK PRIMARY KEY ( intCoachID )
)
CREATE TABLE TTeamCoaches
(
intTeamCoachID INTEGER NOT NULL
,intTeamID INTEGER NOT NULL
,intCoachID INTEGER NOT NULL
,CONSTRAINT TTeamCoaches_PK PRIMARY KEY ( intTeamCoachID )
)
CREATE TABLE TPlayers
(
intPlayerID INTEGER NOT NULL
,strFirstName VARCHAR(50) NOT NULL
,strMiddleName varchar(50) not null
,strLastName VARCHAR(50) NOT NULL
,strEmail VARCHAR(50) NOT NULL
,intShirtSizeID INTEGER NOT NULL
,intPantSizeID INTEGER NOT NULL
,intSockSizeID INTEGER NOT NULL
,strCity VARCHAR(50) NOT NULL
,intStateID INTEGER NOT NULL
,intGenderID INTEGER NOT NULL
,intAgeGroupID INTEGER NOT NULL
,strAddress varchar(50) not null
,strZip varchar(50) not null
,CONSTRAINT TPlayers_PK PRIMARY KEY ( intPlayerID )
)
CREATE TABLE TTeamPlayers
(
intTeamPlayerID INTEGER NOT NULL
,intTeamID INTEGER NOT NULL
,intPlayerID INTEGER NOT NULL
,CONSTRAINT TTeamPlayers_PK PRIMARY KEY ( intTeamPlayerID )
)
CREATE TABLE Z_TeamPlayers
(
intTeamPlayerAuditID INTEGER IDENTITY NOT NULL
,intTeamPlayerID INTEGER NOT NULL
,intTeamID INTEGER NOT NULL
,intPlayerID INTEGER NOT NULL
,UpdatedBy VARCHAR(128) NOT NULL
,UpdatedOn DATETIME NOT NULL
,strAction VARCHAR(1) NOT NULL
,strModified_Reason VARCHAR(1000)
,CONSTRAINT Z_TeamPlayers_PK PRIMARY KEY ( intTeamPlayerAuditID )
)
CREATE TABLE Z_TeamCoaches
(
intTeamCoachAuditID INTEGER IDENTITY NOT NULL
,intTeamCoachID INTEGER NOT NULL
,intTeamID INTEGER NOT NULL
,intCoachID INTEGER NOT NULL
,CONSTRAINT Z_TeamCoaches_PK PRIMARY KEY ( intTeamCoachAuditID )
)
CREATE TABLE Z_Teams
(
intTeamAuditID INTEGER IDENTITY NOT NULL
,intTeamID INTEGER NOT NULL
,strTeam VARCHAR(50) NOT NULL
,UpdatedBy VARCHAR(128) NOT NULL
,UpdatedOn DATETIME NOT NULL
,strAction VARCHAR(1) NOT NULL
,strModified_Reason VARCHAR(1000)
,CONSTRAINT Z_Teams_PK PRIMARY KEY ( intTeamAuditID )
)
CREATE TABLE Z_Players
(
intPlayerAuditID INTEGER IDENTITY NOT NULL
,intPlayerID INTEGER NOT NULL
,strFirstName VARCHAR(50) NOT NULL
,strLastName VARCHAR(50) NOT NULL
,strEmail VARCHAR(50) NOT NULL
,intShirtSizeID INTEGER NOT NULL
,intPantSizeID INTEGER NOT NULL
,intSockSizeID INTEGER NOT NULL
,strCity VARCHAR(50) NOT NULL
,intStateID INTEGER NOT NULL
,intGenderID INTEGER NOT NULL
,intAgeGroupID INTEGER NOT NULL
,UpdatedBy VARCHAR(128) NOT NULL
,UpdatedOn DATETIME NOT NULL
,strAction VARCHAR(1) NOT NULL
,strModified_Reason VARCHAR(1000)
,CONSTRAINT Z_Players_PK PRIMARY KEY ( intPlayerAuditID )
)
CREATE TABLE Z_Coaches
(
intAuditCoachID INTEGER IDENTITY NOT NULL
,intCoachID INTEGER NOT NULL
,strFirstName VARCHAR(50) NOT NULL
,strLastName VARCHAR(50) NOT NULL
,strCity Varchar(50) not null
,intStateID integer not null
,strPhoneNumber varchar(50) not null
,UpdatedBy VARCHAR(128) NOT NULL
,UpdatedOn DATETIME NOT NULL
,strAction VARCHAR(1) NOT NULL
,strModified_Reason VARCHAR(1000)
,CONSTRAINT Z_Coaches_PK PRIMARY KEY ( intAuditCoachID )
)
CREATE TABLE TUsers
(
intUserID integer not null
,intLoginID integer not null
,intRoleID integer not null
,CONSTRAINT TUsers_PK PRIMARY KEY ( intUserID )
)
CREATE TABLE TRoles
(
intRoleID integer not null
,strRole VARCHAR(50) NOT NULL
,CONSTRAINT TRoles_PK PRIMARY KEY ( intRoleID )
)
CREATE TABLE TLogins
(
intLoginID integer not null
,strLoginName varchar(50) not null
,strPassword VARCHAR(50) NOT NULL
,CONSTRAINT TLogins_PK PRIMARY KEY ( intLoginID )
)
CREATE TABLE TFieldGames
(
intFieldGameID INTEGER NOT NULL
,intFieldID INTEGER NOT NULL
,intTeamID INTEGER NOT NULL
,intRefereeID INTEGER NOT NULL
,CONSTRAINT TFieldGames_PK PRIMARY KEY ( intFieldGameID )
)
-- 1
ALTER TABLE TTeamPlayers ADD CONSTRAINT TTeamPlayers_TPlayers_FK
FOREIGN KEY ( intPlayerID ) REFERENCES TPlayers ( intPlayerID )
-- 2
ALTER TABLE TPlayers ADD CONSTRAINT TPlayers_TShirtSizes_FK
FOREIGN KEY ( intShirtSizeID ) REFERENCES TShirtSizes ( intShirtSizeID )
-- 3
ALTER TABLE TPlayers ADD CONSTRAINT TPlayers_TPantSizes_FK
FOREIGN KEY ( intPantSizeID ) REFERENCES TPantSizes ( intPantSizeID )
-- 4
ALTER TABLE TPlayers ADD CONSTRAINT TPlayers_TSockSizes_FK
FOREIGN KEY ( intSockSizeID ) REFERENCES TSockSizes ( intSockSizeID )
-- 5
ALTER TABLE TPlayers ADD CONSTRAINT TPlayers_TStates_FK
FOREIGN KEY ( intStateID ) REFERENCES TStates ( intStateID )
-- 6
ALTER TABLE TPlayers ADD CONSTRAINT TPlayers_TGenders_FK
FOREIGN KEY ( intGenderID ) REFERENCES TGenders ( intGenderID )
-- 7
ALTER TABLE TPlayers ADD CONSTRAINT TPlayers_TAgeGroups_FK
FOREIGN KEY ( intAgeGroupID ) REFERENCES TAgeGroups ( intAgeGroupID )
-- 8
ALTER TABLE TTeamCoaches ADD CONSTRAINT TTeamCoaches_TCoaches_FK
FOREIGN KEY ( intCoachID ) REFERENCES TCoaches ( intCoachID )
-- 9
ALTER TABLE TFieldGames ADD CONSTRAINT TFieldGames_TFields_FK
FOREIGN KEY ( intFieldID ) REFERENCES TFields ( intFieldID )
-- 10
ALTER TABLE TFieldGames ADD CONSTRAINT TFieldGames_TReferees_FK
FOREIGN KEY ( intRefereeID ) REFERENCES TReferees ( intRefereeID )
--11
ALTER TABLE TUsers ADD CONSTRAINT TUsers_TLogins_FK
FOREIGN KEY ( intLoginID ) REFERENCES TLogins ( intLoginID )
-- 12
ALTER TABLE TUsers ADD CONSTRAINT TUsers_TRoles_FK
FOREIGN KEY ( intRoleID ) REFERENCES TRoles ( intRoleID )
-- 13
ALTER TABLE TTeamPlayers ADD CONSTRAINT TTeamPlayers_TTeams_FK
FOREIGN KEY ( intTeamID ) REFERENCES TTeams ( intTeamID )
-- 14
ALTER TABLE TTeamCoaches ADD CONSTRAINT TTeamCoaches_TTeams_FK
FOREIGN KEY ( intTeamID ) REFERENCES TTeams ( intTeamID )
-- 15
ALTER TABLE TCoaches ADD CONSTRAINT TCoaches_TShirtSizes_FK
FOREIGN KEY ( intShirtSizeID ) REFERENCES TShirtSizes ( intShirtSizeID )
--16
ALTER TABLE TCoaches ADD CONSTRAINT TCoaches_TStates_FK
FOREIGN KEY ( intStateID ) REFERENCES TStates ( intStateID )
Since there are no foreign keys in your scheme, the order won't matter. This is what those foreign keys are for: knowing about relations and protect your structure. Without the foreign keys, the database cannot know anything about the structure, not keep you away from destroying the structure. You have to take care of the structure until you add those foreign keys.
Since you're learning, the easiest approach is the technique used by SSMS for scripting. First, drop the foreign keys in one batch (example). Then drop the tables. Not certain what your focus in learning is at this point, but you should master tsql first before you attempt to script DDL at any level of complexity. Given what you have described, you are likely in over your head and should concentrate on gaining skill/experience using a well-designed database first - e.g., AdventureWorks or World Wide Importers.

SQL Server Foreign Key Constraint References Invalid Table

I have the following code:
CREATE TABLE _CLIENT
(
client_id int ,
client_name varchar(50),
type varchar(50),
constraint _CLIENT_pk PRIMARY KEY(client_id),
constraint _CLIENT_ch CHECK (client_id>0),
typee_id INT NOT NULL REFERENCES CLIENT_TYPE(typee_id)
)
CREATE TABLE CLIENT_TYPE
(
typee_id int NOT NULL,
name_type varchar(50),
constraint CLIENT_TYPE_pk PRIMARY KEY(typee_id)
)
The foreign key throws an error saying:
Foreign key 'FK__Number__Name__1CF15040' references invalid table 'Users.Name'
what's the wrong here?
I don't know what exact error message you are getting, but you have error in the current script and I think you mean this error:
Foreign key 'FK___CLIENT__typee_i__55BFB948' references invalid table
'CLIENT_TYPE'.
You should first create CLIENT_TYPE table, so the script should look like:
CREATE TABLE CLIENT_TYPE
(
typee_id INT NOT NULL ,
name_type VARCHAR(50) ,
CONSTRAINT CLIENT_TYPE_pk PRIMARY KEY ( typee_id )
)
CREATE TABLE _CLIENT
(
client_id INT ,
client_name VARCHAR(50) ,
type VARCHAR(50) ,
CONSTRAINT _CLIENT_pk PRIMARY KEY ( client_id ) ,
CONSTRAINT _CLIENT_ch CHECK ( client_id > 0 ) ,
typee_id INT NOT NULL
REFERENCES CLIENT_TYPE ( typee_id )
)
As a general rule, you should first create base tables and then tables which depend on those ones.

Can not create table, errno: 150

What is bad in these queries for creating tables?
CREATE TABLE IF NOT EXISTS `CVM`.`CANDIDATE` (
`ID` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT ,
`FULL_NAME` VARCHAR(64) NOT NULL ,
`HR_INTERVIEW_DATE` DATE NULL ,
`JOB_SEARCH_STATUS` TINYINT(1) NULL ,
`REFERENCES_OPTIONAL` TEXT NULL ,
`AVAILABILITY` TEXT NULL ,
`LOCATION` VARCHAR(200) NULL ,
`TRIP` TEXT NULL ,
`INTERPERSONAL_RISKS` TEXT NULL ,
`TECHNICAL_INTERVIEW_DATE` DATE NULL ,
`EXPERIENCE_IT` TINYINT UNSIGNED NULL ,
`EXPERIENCE_JAVA` TINYINT UNSIGNED NULL ,
`ENGLISH_CHECK_DATE` DATE NULL ,
`ENGLISH_READINESS_DIALOGUE` VARCHAR(100) NULL ,
`ENGLISH_TIME_IMPROVMENT` TINYINT UNSIGNED NULL ,
`ENGLISH_LEVEL_ID` INT NULL ,
`LEVEL_ID` INT NULL ,
`DESIRED_POSITIONS` VARCHAR(100) NULL ,
`HR_COMMENT` TEXT NULL ,
`EXPERT_COMMENT` TEXT NULL ,
`FOREIGN_PASSPORT_ID` INT(11) UNSIGNED NULL ,
`SALARY_ID` INT(11) UNSIGNED NULL ,
`SSE_INFO_ID` INT(11) UNSIGNED NULL ,
`EXPERT_NAME` VARCHAR(100) NULL ,
`HR_NAME` VARCHAR(100) NULL ,
`TEACHER_NAME` VARCHAR(100) NULL ,
PRIMARY KEY (`ID`) ,
INDEX `FK_CANDIDATE_ENGLISH_LEVEL1` (`ENGLISH_LEVEL_ID` ASC) ,
INDEX `fk_CANDIDATE_LEVEL1` (`LEVEL_ID` ASC) ,
INDEX `fk_CANDIDATE_FOREIGN_PASSPORT1` (`FOREIGN_PASSPORT_ID` ASC) ,
INDEX `fk_CANDIDATE_SALARY1` (`SALARY_ID` ASC) ,
INDEX `fk_CANDIDATE_SSE_INFO1` (`SSE_INFO_ID` ASC) ,
CONSTRAINT `FK_CANDIDATE_ENGLISH_LEVEL1`
FOREIGN KEY (`ENGLISH_LEVEL_ID` )
REFERENCES `CVM`.`ENGLISH_LEVEL` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_CANDIDATE_LEVEL1`
FOREIGN KEY (`LEVEL_ID` )
REFERENCES `CVM`.`LEVEL` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_CANDIDATE_FOREIGN_PASSPORT1`
FOREIGN KEY (`FOREIGN_PASSPORT_ID` )
REFERENCES `CVM`.`FOREIGN_PASSPORT` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_CANDIDATE_SALARY1`
FOREIGN KEY (`SALARY_ID` )
REFERENCES `CVM`.`SALARY` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_CANDIDATE_SSE_INFO1`
FOREIGN KEY (`SSE_INFO_ID` )
REFERENCES `CVM`.`SSE_INFO` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `CVM`.`CANDIDATE_HISTORY`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `CVM`.`CANDIDATE_HISTORY` (
`ID` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT ,
`CANDIDATE_ID` INT(11) UNSIGNED NOT NULL ,
PRIMARY KEY (`ID`) ,
INDEX `fk_CANDIDATE_HISTORY_CANDIDATE1` (`CANDIDATE_ID` ASC) ,
CONSTRAINT `fk_CANDIDATE_HISTORY_CANDIDATE1`
FOREIGN KEY (`CANDIDATE_ID` )
REFERENCES `CVM`.`CANDIDATE` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `CVM`.`CANDIDATE_CHANGES`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `CVM`.`CANDIDATE_CHANGES` (
`ID` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT ,
`FIELD` VARCHAR(100) NULL ,
`CHANGED_VALUE` TEXT NULL ,
PRIMARY KEY (`ID`) )
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `CVM`.`CANDIDATE_HISTORY_has_CANDIDATE_CHANGES`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `CVM`.`CANDIDATE_HISTORY_has_CANDIDATE_CHANGES` (
`CANDIDATE_HISTORY_ID` INT(11) UNSIGNED NOT NULL ,
`CANDIDATE_CHANGES_ID` INT(11) UNSIGNED NOT NULL ,
PRIMARY KEY (`CANDIDATE_HISTORY_ID`, `CANDIDATE_CHANGES_ID`) ,
INDEX `fk_CANDIDATE_HISTORY_has_CANDIDATE_CHANGES_CANDIDATE_CHANGES1` (`CANDIDATE_CHANGES_ID` ASC) ,
CONSTRAINT `fk_CANDIDATE_HISTORY_has_CANDIDATE_CHANGES_CANDIDATE_HISTORY1`
FOREIGN KEY (`CANDIDATE_HISTORY_ID` )
REFERENCES `CVM`.`CANDIDATE_HISTORY` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_CANDIDATE_HISTORY_has_CANDIDATE_CHANGES_CANDIDATE_CHANGES1`
FOREIGN KEY (`CANDIDATE_CHANGES_ID` )
REFERENCES `CVM`.`CANDIDATE_CHANGES` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
In SQL workbench its all ok, but using maven-sql-plugin it failed to create table candidate_history_has_candidate_changes. All names are less than 64 symbols. Please, help!
Try to narrow down the possible causes, starting with a simple create table. Try creating this simple table with and without backtick quotes in case the plugin isn't handling them properly.
Check you are logging in as the same user in both cases.
See if there are any leftovers from the tables. CREATE IF NOT EXIST does nothing if the tables already exist. (see asker's comments for more info).
Lots of possible answers here:
http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-create-table-mydbsql-328_45frm-errno-150/