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.
Related
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
I have created a model in MySQL workbench, when I want to forward engineer it to create the "create" and "insert" script I get the following error:
ERROR:
Executing SQL script in server
ERROR: Error 1366: Incorrect integer value: 'G1' for column 'gebruiker_id' at row 1
SQL Code:
INSERT INTO `databaseher`.`gebruiker` (`gebruiker_id`, `voornaam`, `achternaam`, `E-mail`) VALUES ('G1', 'Ronny', 'Giezen', 'r.giezen#gmail.com')
I don't understand whats wrong with it, because the datatype of the column where the value "G1" inserts into is "VARCHAR(4)". It should be possible to insert both a letter and a number.... At least that's what I thought...
This is the create table:
CREATE TABLE IF NOT EXISTS `databaseher`.`gebruiker` (
`gebruiker_id` VARCHAR(4) NOT NULL,
`voornaam` VARCHAR(25) NOT NULL,
`achternaam` VARCHAR(20) NOT NULL,
`E-mail` VARCHAR(30) NOT NULL,
PRIMARY KEY (`gebruiker_id`),
UNIQUE INDEX `E-mail_UNIQUE` (`E-mail` ASC) VISIBLE)
ENGINE = InnoDB;
If someone could help, that'll be awesome.
Thank you in advance!
Just a guess here because we don't have the full picture.
Can you run this:
Drop table 'databaseher'.'gebruiker'
And after recreate the table
CREATE TABLE IF NOT EXISTS `databaseher`.`gebruiker` (
`gebruiker_id` VARCHAR(4) NOT NULL,
`voornaam` VARCHAR(25) NOT NULL,
`achternaam` VARCHAR(20) NOT NULL,
`E-mail` VARCHAR(30) NOT NULL,
PRIMARY KEY (`gebruiker_id`),
UNIQUE INDEX `E-mail_UNIQUE` (`E-mail` ASC) VISIBLE)
ENGINE = InnoDB;
rerun the insert.
I am guessing that the table was initially created with the column gebruiker as integer
Sorry if this is an easy question, I am coming to MySQL from SQL Server.
When I execute my create statement it contains nvarchar but commits to the database as varchar. Even in my alter statement afterwards the column does not change at all. Does the collation or DB engine make a difference?
During execution I am not encountering any issues in results, other than the fact the column changes datatype. I attached a screencast of my activity http://screencast.com/t/wc94oei2
I have not been able to find anyone with similar issues through my Google searches
Did you mean, this..
CREATE TABLE stars (
idstars int(11) NOT NULL AUTO_INCREMENT,
Name nvarchar(200) DEFAULT NULL,
PRIMARY KEY (idstars),
UNIQUE KEY Name_UNIQUE (Name)
)
----turns to---
CREATE TABLE stars (
idstars int(11) NOT NULL AUTO_INCREMENT,
Name varchar(200) DEFAULT NULL,
PRIMARY KEY (idstars),
UNIQUE KEY Name_UNIQUE (Name)
)
For the following table:
I'd like to add a constraint that if IsBanned flag is set to true, the BannedOn field cannot be left empty (cannot be set to null).
How can I do this in MySQL? Here's my CREATE syntax:
CREATE TABLE IF NOT EXISTS `fa_ranking_system`.`Player` (
`PlayerID` INT NOT NULL AUTO_INCREMENT,
`FK_ServerID` INT NOT NULL,
`PlayerName` VARCHAR(15) NOT NULL,
`RegDate` DATETIME NOT NULL,
`IsBanned` TINYINT(1) NOT NULL,
`LastUpdatedOn` DATETIME NOT NULL,
`LastUpdatedBy` VARCHAR(20) NOT NULL,
`BannedOn` DATETIME NULL,
PRIMARY KEY (`PlayerID`, `FK_ServerID`),
INDEX `fk_Player_Server_idx` (`FK_ServerID` ASC),
CONSTRAINT `fk_Player_Server`
FOREIGN KEY (`FK_ServerID`)
REFERENCES `fa_ranking_system`.`Server` (`ServerID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
Actually, you can not define conditional structures in DDL syntax. Your field can be either NULL or NOT NULL - there's no third option (and it cannot depend of another field in structure)
But you can still emulate desired behavior via triggers. You can interrupt UPDATE/INSERT statement if incoming data is invalid in terms of your logic. That can be done via:
CREATE TRIGGER `bannedOnCheck`
BEFORE INSERT ON `fa_ranking_system`.`Player`
FOR EACH ROW
BEGIN
IF(new.IsBanned && new.BannedOn IS NULL) THEN
SIGNAL 'Integrity check failed: can not set banned without ban date'
END IF
END
I'm trying to create a table with this function in Codeigniter
public function createTable($connectionString) {
$createString = "CREATE TABLE {$this->getTabela()} (
`data` datetime NOT NULL,
`idempregado` varchar(45) DEFAULT NULL,
`nif` varchar(15) DEFAULT NULL,
`idsociedade` bigint(20) DEFAULT NULL,
`tipo` varchar(45) DEFAULT NULL,
PRIMARY KEY (`data`),
KEY `fk_assiduidade_user1` (`idempregado`,`nif`,`idsociedade`),
CONSTRAINT `fk_assiduidade_user1` FOREIGN KEY (`idempregado`, `nif`, `idsociedade`) REFERENCES `user` (`idempregado`, `nif`, `idsociedade`) ON DELETE NO ACTION ON UPDATE NO ACTION
)
ENGINE=FEDERATED
DEFAULT CHARSET=utf8
CONNECTION='$connectionString'";
var_dump($createString);
var_dump($this->getDbConnect()->conn_id);
var_dump($this->getDbConnect()->query($createString));
}
But the query is always returning False.
As you guys can see i already made 3 var_dumps to check if its all OK.
Ca you guys help me get to the point where this don't execute the query?
Regards,Elkas
I just found the problem.
After talking with technicians at the Data center (because i dont have access to any logs) i found that they have the FEDERATED engine disabled.
Problem Solved.
Thanks for the tips.