I found how to make sql developer connect to a mysql server and then I made a database. The problem I now have is that I cannot add my tables to it. Is it a syntax problem or am I doing something wrong? I have used (use database;) but now I see and error on some lines. Like in line 352, but it looks fine....
CREATE TABLE acctmanager
(amid VARCHAR2(4) PRIMARY KEY,
amfirst VARCHAR2(12) NOT NULL,
amlast VARCHAR2(12) NOT NULL,
amedate DATE DEFAULT SYSDATE,
region CHAR(2) NOT NULL);
there is no varchar2 in MySQL
replace varchar2 with varchar
Related
I try do create a simple mysql database with Flyway migration, but it doesn't going well.
I have created my .sql it named as V1_0__init.sql and I've written some sql commands there:
CREATE TABLE User (
id INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
created DATE NOT NULL,
username varchar(15) NOT NULL,
password varchar(15) NOT NULL,
email varchar(40) NOT NULL,
status boolean NOT NULL,
unique(username)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
I think it should be fine, but I have two errors, one at the first line (CREATE TABLE) and another at the fourth line (created DATE NOT NULL).
The error message says:
Invalid or Incomplete statement
Expected one of the following: ALGORITHM DEFINER SQL VIEW
(At the 'created DATE NOT NULL' line have a similar message, the only difference is this: Algoritm definer OR sql view)
I've tried to fix these but it didn't go well.
Anyone could help me how to fix this?
Maybe did I miss something? Should I do something in application.properties?
I have database which works on MySql. And i need to copy it to another computer where there is only management studio. i create .sql file from MySql and tried to run it in studio but always have syntax errors.
How to do it correctly?
CREATE TABLE branches (
idbranches int(11) NOT NULL AUTO_INCREMENT,
address varchar(200) NOT NULL,
e.g. incorrect syntax for "AUTO_INCREMENT"
The SQL Server syntax is:
CREATE TABLE branches (
idbranches int identity(1, 1) not null,
address varchar(200) NOT NULL
);
I need this code to run the instant the professor hits the F5 button.
I created a database and I have a problem with the USE statement
SQL just can't switch to the database that USE statement is calling. it's saying this:
could not locate entry in sysdatabases for database
I tried with square brackets ([]) and it's not helping.
The project is about Car Service and its a school project.
I just need that USE statement to run or some other solution so the code can run without error and in one click on F5.
USE master;
IF DB_ID('ServisAutomobila') IS NOT NULL
DROP DATABASE ServisAutomobila;
GO
CREATE DATABASE ServisAutomobila;
USE ServisAutomobila
go
CREATE TABLE Automobil
(
Automobil_ID int identity (1,1) not null,
Model nvarchar (50) not null,
GodinaProizvodnje nvarchar(50) not null,
RegistarskiBroj nvarchar (50) unique not null,
BrojMotora nvarchar (50) unique not null,
BrojSasije nvarchar (50) unique not null,
Kvar nvarchar (250) not null,
TipAutomobila_ID int not null,
Zemlja_ID int not null,
Vlasnik_ID int not null
)
CREATE TABLE Zemlja
(
Zemlja_ID int identity (1,1) not null,
Zemlja nvarchar (50) not null
)
The GO keyword is a batch terminator. So in your example:
CREATE DATABASE ServisAutomobila;
USE ServisAutomobila
go
The batch is executed as one and results in that particular error because the database engine tries do use database ServisAutomobila which does not exists yet. This means that you must add that extra GO suggested in the previous comments before you can use the newly created database:
CREATE DATABASE ServisAutomobila;
GO;
USE ServisAutomobila;
GO;
I am having the following error when trying to execute the following code in phpMyAdmin. I am using WAMP Server with MySQL version 5.5.8 ::
The error is:
#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 'NUMERIC(6) not null, payee VARCHAR2(20) not null, amount DECIMAL(6,2) no' at line 3
the SQL is:
CREATE TABLE checks
(
check NUMERIC(6) not null,
payee VARCHAR2(20) not null,
amount DECIMAL(6,2) not null,
remarks VARCHAR2(20) not null
)
EDIT
I am also trying to execute this but it gives also error:
CREATE TABLE deposits
(
deposit NUMBER(8),
whopaid VARCHAR(25),
amount DECIMAL(6,2),
remarks VARCHAR(20)
)
You need to escape check with backticks since it is a reserved word. And in MySQL there is no varchar2 data type, just varchar.
CREATE TABLE checks
(
`check` NUMERIC(6) not null,
payee VARCHAR(20) not null,
amount DECIMAL(6,2) not null,
remarks VARCHAR(20) not null
)
Also replace NUMBER with NUMERIC in your 2nd create statement.
CREATE TABLE deposits
(
deposit NUMERIC(8),
whopaid VARCHAR(25),
amount DECIMAL(6,2),
remarks VARCHAR(20)
)
SQLFiddle example
See MySQL String data types and MySQL numeric data types
check is a reserved work, that's why you have this error
you need to put quotes around it
CHECK is a reserved keyword in mysql. If you choose a different name it should work fine.
http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html
I am using the mysql admin GUI tool to create a table. Here is the query language that results in an error:
CREATE TABLE `environment`.`moisture` (
`city_id` INT,
`date_holding` VARCHAR,
`time_holding` VARCHAR,
`open` REAL,
`high` REAL,
`low` REAL,
`close` REAL,
)
CHARACTER SET utf8;
My date and time are not of the format mysql likes so I selected VARCHAR as the type for those columns and referred to them as holding columns until I can run queries to make the necessary conversions.
When I try to execute this via the GUI I get the following:
Error executing SQL commands to create table.
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 'NOT NULL,
`time_holding` VARCHAR NOT NULL,
`open` REAL NOT NULL,
`high` RE' at line 3 (error 1064)
Any idea why I am getting this? I have checked to see if I am using any reserved words but that does not seem to be the case.
Your help would be greatly appreciated.
The first error you have is due to that VARCHAR fields need a length like this: VARCHAR(30).
The second error (you'll get if you fix the 2 varchars) is the comma before the last parenthesis.
CREATE TABLE `environment`.`moisture` (
`city_id` INT,
`date_holding` VARCHAR(30), --or whatever length you want
`time_holding` VARCHAR(20), --same
`open` REAL,
`high` REAL,
`low` REAL,
`close` REAL --- no comma here
)
CHARACTER SET utf8;
Side note: You do know that MySQL has specific types to handle dates and times, don't you? So you could have:
CREATE TABLE `environment`.`moisture` (
`city_id` INT,
`date_holding` date,
`time_holding` time,
...