Error 1064 from trying to forward engineer an ERD - sql

I'm still learning SQL at the moment and i keep getting this error when i try to forward engineer my tables. Could really use some assistance on figuring out what's causing the error.
Executing SQL script in server
ERROR: Error 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 'VISIBLE,
CONSTRAINT fk_Player_Team1
FOREIGN KEY (team_id)
REFERENC' at line 11
SQL Code:
CREATE TABLE IF NOT EXISTS `sts18`.`Player` (
`player_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`team_id` INT UNSIGNED NOT NULL,
`player_lname` VARCHAR(45) NOT NULL,
`player_fname` VARCHAR(45) NOT NULL,
`player_age` TINYINT UNSIGNED NOT NULL,
`player_phone` BIGINT UNSIGNED NOT NULL,
`player_email` VARCHAR(100) NULL,
`player_notes` VARCHAR(255) NULL,
PRIMARY KEY (`player_id`),
INDEX `fk_Player_Team1_idx` (`team_id` ASC) VISIBLE,
CONSTRAINT `fk_Player_Team1`
FOREIGN KEY (`team_id`)
REFERENCES `sts18`.`Team` (`team_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
SQL script execution finished: statements: 17 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch

Related

postgresql syntax error at or near "EXERCISE_ID" at character 1

for postgres in Docker I use some .sql files to build the database. A script concatenates all files in the right order. It doesn't start the Postgres-image, because there is a syntax error. I don't see it, so maybe one of you do it?
LOG from IntelliJ:
2018-03-25 11:05:32.628 UTC [73] ERROR: syntax error at or near "EXERCISE_ID" at character 1
2018-03-25 11:05:32.628 UTC [73] STATEMENT: EXERCISE_ID SERIAL NOT NULL PRIMARY KEY,
EXERCISE_NAME VARCHAR(50) NOT NULL,
EXERCISE_DESCRIPTION VARCHAR(300) NOT NULL,
EXERCISE_SUBCATEGORY INT NOT NULL REFERENCES TL_CATEGORIES(CATEGORY_ID),
EXERCISE_DATE_ADD DATE NOT NULL,
EXERCISE_DATE_CHANGED DATE NOT NULL,
EXERCISE_LOCATION_URL VARCHAR(300) NOT NULL,
EXERCISE_STATUS VARCHAR(1) NOT NULL DEFAULT '0'
);
psql:/docker-entrypoint-initdb.d/sqlinit.sql:47: ERROR: syntax error at or near "EXERCISE_ID"
LINE 1: EXERCISE_ID SERIAL NOT NULL PRIMARY KEY,
^
.sql:
CREATE TABLE IF NOT EXISTS TL_EXERCISES (
EXERCISE_ID SERIAL NOT NULL PRIMARY KEY,
EXERCISE_NAME VARCHAR(50) NOT NULL,
EXERCISE_DESCRIPTION VARCHAR(300) NOT NULL,
EXERCISE_SUBCATEGORY INT NOT NULL REFERENCES TL_CATEGORIES(CATEGORY_ID),
EXERCISE_DATE_ADD DATE NOT NULL,
EXERCISE_DATE_CHANGED DATE NOT NULL,
EXERCISE_LOCATION_URL VARCHAR(300) NOT NULL,
EXERCISE_STATUS VARCHAR(1) NOT NULL DEFAULT '0'
);
Analysis from IntelliJ did not find any errors.
I would be very happy, if you would help me.
2018-03-25 11:05:32.628 UTC [73] STATEMENT: EXERCISE_ID SERIAL NOT NULL PRIMARY KEY,
...
LINE 1: EXERCISE_ID SERIAL NOT NULL PRIMARY KEY,
Somehow you seem to have lost the "CREATE TABLE" line from your sql. I've no idea how I'm afraid.

Length or precision specification 0 is invalid

I have an MFC app which run some SQL statements, and I have run them on several PCs, without any problem.
But, I have met an PC, where when I have tried to run these SQLs, I have encountered an strange error (strange for me, I know SQL a little):
Length or precision specification 0 is invalid
This error fired on the following SQL:
CREATE TABLE mytable (
nmytable_ID int IDENTITY (1, 1) PRIMARY KEY NOT NULL,
nAsset_ID int FOREIGN KEY REFERENCES t_asset (nAsset_ID) DEFAULT NULL,
dtInit date NOT NULL,
dRest decimal(10, 2) NULL,
nOdo int NULL,
sObs varchar(1024) NULL,
dtDateC datetime2(0) NULL,
dtDateU datetime2(0) NULL,
nUserC int FOREIGN KEY REFERENCES ntp_appuserx (nAppUserx_ID) DEFAULT NULL,
nUserU int FOREIGN KEY REFERENCES ntp_appuserx (nAppUserx_ID) DEFAULT NULL,
CONSTRAINT nAsset_ID_mytable UNIQUE (nAsset_ID, dtInit)
)
Ok, I have changed DATETIME2(0) data type to DATETIME, but then I get the following error:
DATE data type is unknown
There is a question: why this error(s), but on an PC, and not for others ? Is there some local settings which affect my app ? I am using SQL Server 2012.
Solved
I have tried to create the table on older DB installed on this PC, without to notice that.

Error 1064 sql phpmyadmin

This is my sql query:
CREATE TABLE estados (
id int IDENTITY(1,1) PRIMARY KEY,
nombre VARCHAR(20) NOT NULL,
paridad int NOT NULL
);
and it keeps telling me:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use
near '(1,1) PRIMARY KEY,
nombre VARCHAR(20) NOT NULL,
paridad int NOT NULL
I don't know why is this, I am using 10.1.10-MariaDB. I don't know why I have syntax error, and if this has to do with the versions.
IDENTITY is for SQL Server. You should use AUTO_INCREMENT instead:
CREATE TABLE estados (
id int AUTO_INCREMENT PRIMARY KEY,
nombre VARCHAR(20) NOT NULL,
paridad int NOT NULL
);

Executing SQL script in server ERROR: Error 1215: Cannot add foreign key constraint

I've checked other concerns like this. Checked if there were duplicates-none, if same data type -yep. relationships- yep. Not using "On Delete Set Null" checked.
I'm still lost how this error came to be
Executing SQL script in server
ERROR: Error 1215: Cannot add foreign key constraint
-- Table Apo.PurchasingOrder
CREATE TABLE IF NOT EXISTS Apo.PurchasingOrder (
PurchaseNo. INT NOT NULL AUTO_INCREMENT,
ModelNo. INT NULL,
UnitPrice INT NULL,
Product/Name VARCHAR(45) NULL,
Quantity INT NULL,
Source VARCHAR(45) NULL,
PRIMARY KEY (PurchaseNo.),
INDEX Source (Source ASC),
CONSTRAINT Supplier_Source
FOREIGN KEY (`PurchaseNo.`)
REFERENCES `Apo`.`Supplier` (`SupplierID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
SQL script execution finished: statements: 9 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
Could you check whether all your PurchaseNo values in Apo.PurchasingOrder are valid values of SupplierID in Apo.Supplier?

Install script MySQL syntax error "You have an error in your SQL syntax; [...] "

I have an install script on my website, and when i run it, it gives me thsi error:
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 'CREATE TABLE active_guests ( ip varchar(15) collate latin1_general_' at line 2
Here is the code where it seems to bug:
$sql = 'SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
CREATE TABLE `active_guests` (
`ip` varchar(15) collate latin1_general_ci NOT NULL,
`timestamp` int(11) unsigned NOT NULL,
PRIMARY KEY (`ip`)
);';
mysql_query($sql,$con) or die(mysql_error());
$sql = 'CREATE TABLE `active_users` (
`username` varchar(30) collate latin1_general_ci NOT NULL,
`timestamp` int(11) unsigned NOT NULL,
PRIMARY KEY (`username`)
);';
mysql_query($sql,$con) or die(mysql_error());
$sql = 'CREATE TABLE `banned_users` (
`username` varchar(30) collate latin1_general_ci NOT NULL,
`timestamp` int(11) unsigned NOT NULL,
PRIMARY KEY (`username`)
);';
It continues even more after that, but basically it's this. Anyone could clear things up? Thanks in advance!
You can only run one statement per call to mysql_query().
So you have to run SET SQL_MODE ... and then separately run the first CREATE TABLE ...
Re your comment: I recommend that you stick with running one statement per call to mysql_query() or its equivalent in mysqli or PDO. There's really no significant downside to doing it, and it's a good way to prevent some forms of SQL injection.