Access Database 2016 syntax error in CONSTRAINT clause - ms-access

I was running this SQL create table in access 2016 database but I get syntax error in CONSTRAINT clause. It appears correct to me. What may be the error in the constraint clause.
CREATE TABLE COMPUTER(
SerialNumber Number NOT NULL,
Make Text(12) NOT NULL,
Model Text(24) NOT NULL,
ProcessorType Text(24) NULL,
ProcessorSpeed Number NOT NULL,
MainMemory Text(15) NOT NULL,
DiskSize Text(15) NOT NULL,
primary key(SerialNumber),
CONSTRAINT MAKE_CHECK (Make IN ('Dell', 'Gateway', 'HP', 'Other')),
CONSTRAINT SPEED_CHECK CHECK(ProcessorSpeed BETWEEN 1.0 AND 4.0))

Use the correct syntax:
CONSTRAINT MAKE_CHECK CHECK(Make IN ('Dell', 'Gateway', 'HP', 'Other')),

Related

MYSQL FOREIGN KEY ISSUES

I am trying to create a table which references two other tables that I have planned to make, but have not made yet. I am wondering if that is the issue here or if there is a syntax error that I am missing. If anyone can help me out it would be greatly appreciated
mysql> CREATE TABLE items (
items$id INT NOT NULL AUTO_INCREMENT,
sales$id INT NOT NULL AUTO_INCREMENT,
img$id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
desc VARCHAR(255) NOT NULL,
PRIMARY KEY(items$id),
FOREIGN KEY(sales$id) REFERENCES sales(sales$id),
FOREIGN KEY(img$id) REFERENCES image(img$id)
ERROR 1064 (42000): 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 'desc VARCHAR(255) NOT NULL,
PRIMARY KEY(items$id),
FOREIGN KEY(sales$id) REFEREN' at line 6
I tried to remove the references, as in just do 'FOREIGN KEY(sales$id)' and 'FOREIGN KEY(img$id)' to see if that would work (I am new to mysql), but that also did not work. Any help is appreciated.
The problem is your field name: desc
desc is a keyword in mysql see here
Your sql would be better like this:
CREATE TABLE items ( items$id INT NOT NULL AUTO_INCREMENT, sales$id INT NOT NULL AUTO_INCREMENT, img$id INT NOT NULL AUTO_INCREMENT, name VARCHAR(255) NOT NULL, descr VARCHAR(255) NOT NULL, PRIMARY KEY(items$id),
FOREIGN KEY(sales$id) REFERENCES sales(sales$id),
FOREIGN KEY(img$id) REFERENCES image(img$id))
Ps: you missed closing bracket ')' at the end of your sql query.

The duplicate key value is (<NULL>, <NULL>)

So I'm trying to migrate a table from MySQL to MSSQL (sql server migration assistant MySQL), but I get this error:
Migrating data...
Analyzing metadata...
Preparing table testreportingdebug.testcase...
Preparing data migration package...
Starting data migration Engine
Starting data migration...
The data migration engine is migrating table '`testreportingdebug`.`testcase`': > [SwMetrics].[testreportingdebug].[testcase], 8855 rows total
Violation of UNIQUE KEY constraint 'testcase$Unique'. Cannot insert duplicate key in object 'testreportingdebug.testcase'. The duplicate key value is (<NULL>, <NULL>).
Errors: Violation of UNIQUE KEY constraint 'testcase$Unique'. Cannot insert duplicate key in object 'testreportingdebug.testcase'. The duplicate key value is (<NULL>, <NULL>).
Completing migration of table `testreportingdebug`.`testcase`...
Migration complete for table '`testreportingdebug`.`testcase`': > [SwMetrics].[testreportingdebug].[testcase], 0 rows migrated (Elapsed Time = 00:00:00:01:352).
Data migration operation has finished.
0 table(s) successfully migrated.
0 table(s) partially migrated.
1 table(s) failed to migrate.
I've just copied three rows from my table, and this is what they look like:
'1', 'Pump# TimeToService', NULL, NULL, 'A general test case comment ...', '0'
'2', 'Config.SlaveMinimumReplyDelay', NULL, NULL, NULL, '0'
'3', 'Config.RESERVED', NULL, NULL, NULL, '0'
If you are wondering how the colons in the MySQL table is setup, here you go:
Is is because right, left and comment can be null?
DDL of table
CREATE TABLE `testcase` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`TestCaseName` varchar(150) DEFAULT NULL,
`Left` int(11) DEFAULT NULL,
`Right` int(11) DEFAULT NULL,
`Comment` text,
`Hidden` tinyint(4) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `Unique` (`Left`,`Right`)
) ENGINE=InnoDB AUTO_INCREMENT=10580 DEFAULT CHARSET=utf8
Had to remove the Unique part, since their are only NULL.
ALTER TABLE `testreportingdebug`.`testcase`
DROP INDEX `Unique`;
If you want the strict equivalent in SQL Server of your MySQL table you must create it like this :
CREATE TABLE testcase (
id int NOT NULL IDENTITY PRIMARY KEY,
TestCaseName varchar(150),
[Left] int,
[Right] int,
Comment VARCHAR(max),
[Hidden] tinyint DEFAULT 0,
);
CREATE UNIQUE INDEX X_testcase_right_left
ON testcase ([Left], [Right])
WHERE [Left] IS NOT NULL
AND [Right] IS NOT NULL;
By the way, column names "Right", "left", "hidden" are SQL / MS SQL Server reserved words and should not be used at anytime for SQL identifiers (table name, colum name, proc name...)
The complete list can be obtain here

Forward Engineering MySQL Workbench Error 1064

I made a EER diagram and I am trying to Forward Engineer it but I get this error and I can't find the mistake.
Executing SQL script in server ERROR: Error 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 'INDEX
fk_User_Wallets1_idx (Wallets_idWallets ASC) VISIBLE, CONSTRAINT '
at line 13
SQL Code:
CREATE TABLE IF NOT EXISTS `mydb`.`User` (
`idUser` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(45) NULL,
`email` VARCHAR(45) NULL,
`adress` VARCHAR(45) NULL,
`password` VARCHAR(45) NULL,
`saldo` INT NULL,
`date_start` DATETIME NULL,
`date_end` DATETIME NULL,
`Rolls_idRolls` INT NOT NULL,
`Wallets_idWallets` INT NOT NULL,
PRIMARY KEY (`idUser`, `Rolls_idRolls`, `Wallets_idWallets`),
INDEX `fk_User_Rolls1_idx` (`Rolls_idRolls` ASC) VISIBLE,
INDEX `fk_User_Wallets1_idx` (`Wallets_idWallets` ASC) VISIBLE,
CONSTRAINT `fk_User_Rolls1`
FOREIGN KEY (`Rolls_idRolls`)
REFERENCES `mydb`.`Rolls` (`idRolls`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_User_Wallets1`
FOREIGN KEY (`Wallets_idWallets`)
REFERENCES `mydb`.`Wallets` (`idWallets`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
SQL script execution finished: statements: 11 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
This is mysql version issue Remove the VISIBLE. and run the code manually . Or update mysql server and the client into same version .
(Wallets_idWallets ASC) VISIBLE into (Wallets_idWallets ASC)
can you add engine
ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
Before you forward engineering tick the below options and continue the process,
Go to the option section > Under the set options for Database to be created
Skip creation of foreign keys
Skip creation of Indexes as well
generate separate create index statements
Generate Insert statement for table
And continue the forward engineering process.

Error 1064 in SQL script while exporting from MySql workbench

Getting an error in the SQL script while exporting a model from MySQL workbench. Been looking around for a bit but can't find any answers that could help in this specific case.
Trying to export a script created in MySQL workbench to phpMyAdmin. Can anyone see what is wrong with this part of the script?
Executing SQL script in server
ERROR: Error 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 ')
REFERENCES mydb.Staff ()
ON DELETE NO ACTION
ON UPDATE NO ACTI' at line 15
SQL Code
-- -----------------------------------------------------
-- Table `mydb`.`course`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`course` (
`idcourse` INT NOT NULL AUTO_INCREMENT,
`title` VARCHAR(45) NOT NULL,
`describtion` VARCHAR(45) NOT NULL,
`week start` DATE NOT NULL,
`week end` DATE NOT NULL,
`ECTS` INT NOT NULL,
`course responsible` VARCHAR(45) NOT NULL,
`level` VARCHAR(45) NOT NULL,
PRIMARY KEY (`idcourse`),
CONSTRAINT `course responsible`
FOREIGN KEY ()
REFERENCES `mydb`.`Staff` ()
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `level`
FOREIGN KEY ()
REFERENCES `mydb`.`Level` ()
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
Check the foreign key syntax
CREATE TABLE <table_name>(
column1 data_type[(size)] ,
column2 data_type[(size)] ,
constraint(constraint_name)
FOREIGN KEY [column1,column2...]
REFERENCES [primary_key_table] (column_list_of_primary_key_table) ...);

SQL Syntax Error - creating new database

Here's my code, currently got an error at line 3 on the USE statement :
CREATE DATABASE `jamestennisdbTest`;
USE jamestennisdbTest;
DROP TABLE IF EXISTS lessontbl;
CREATE TABLE lessontbl (
LessonID int(11) NOT NULL AUTO_INCREMENT,
LessonName varchar(30) NOT NULL,
LengthOfLesson int(11) NOT NULL,
NoOfPupils int(11) NOT NULL,
LocationID int(11) NOT NULL,
`Type` varchar(45) NOT NULL,
CostPerPupil float NOT NULL,
TotalCost float NOT NULL,
PRIMARY KEY (LessonID),
UNIQUE KEY LessonID_UNIQUE (LessonID),
KEY `fk_Location_lesson-location` (LocationID),
CONSTRAINT `fk_Location_lesson-location` FOREIGN KEY (LocationID) REFERENCES locationstbl (LocationID) ON DELETE NO ACTION ON UPDATE NO ACTION
)
..it goes on but thats not where the errors coming up
..And I am trying to do this through a Delphi ADOQuery (though I dont think that's where the error is)
I believe the 'use' statement is only used in the mysql command line client to switch to another database. If you want to "use" another database, you'll probably need to use some API call or just reconnect directly to the newly created database.