I am trying to create a GUI with a database attached, my SQL table is :
CREATE TABLE IF NOT EXISTS imagerecord (
PId int,
PName varchar(50) not null,
Photo varbinary(max)
)
Clearly I am trying to include an image in the database (atleast, that's what I think I'm doing), however my system is not identifying the 'varbinary' datatype, showing this error :
Error code 1064, SQL state 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 'max) )' at line 4
Please tell me what to do, is there some extra software do I have to install?
You're mixing Microsoft SQL Server syntax for VARBINARY(MAX) with MySQL syntax for CREATE TABLE IF NOT EXISTS. Neither RDBMS implementation supports both of these features.
Microsoft SQL Server supports MAX as a length instead of a specific number, but standard SQL and most other brands don't support this option.
MySQL supports IF NOT EXISTS as an optional modifier, but this is also not standard SQL, and Microsoft doesn't support this extension.
You need to figure out which brand you're using. The fact that MAX gave an error but IF NOT EXISTS did not suggests you are using MySQL. Here are links to the respective documentation pages:
Microsoft SQL Server 2012:
CREATE TABLE
BINARY and VARBINARY
MySQL 5.6:
CREATE TABLE
BINARY and VARBINARY
The maximum length of a VARBINARY in MySQL is 65535. If you need a column that can accept a longer string, you can use MEDIUMBLOB which allows up to 16MB, or LONGBLOB which allows up to 4GB.
Related
i was testing a software on my computer , i have a mysql installed on it . now i have transfered this software to a server . no any mysql command is working
for example this is the command that was working on my computer
SELECT COUNT(*) FROM camera WHERE stored=3;
when i try to execute it on my server here is the result
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 'stored=3' at line 1
but this one is working
SELECT COUNT(*) FROM camera WHERE camera.stored=3;
is there any way to restore it without needing to define the table name ?
Stored is a MySQL Reserved Word, so MySQL thinks you are intending to use that Reserved Word.
When you qualify it with the Table Name, then it knows what you are talking about.
UPDATE: You could wrap stored in back ticks (shown below) so it's treated as text and not a Reserved Word.
SELECT COUNT(*) FROM camera WHERE `stored`=3;
SQL Server Migration Assistant for MySQL (Chinese display error)
I am using SQL Server Migration Assistant for MySQL to migrate from Mysql to SQL Server
After the migration data is completed Chinese display ?? Error display!
迁移工具
Our data is available in four languages
zh_TW
zh_CN
pt_PT
en
I finally solved the problem completely
When I link SQL server data, I set charset = utf8, but there are still individual displays in Chinese Simplified "?"
At last, we set the field type to nvarchar (max). At first, I knew that modifying the field type could solve the problem, but we were migrating data and could not modify the field type. Using symfony schema update to generate SQL statements also did not support nvarchar (max). At last, we modified the source code of generating SQL statements. Using text type, we could compile nvarchar (max)
enter image description here
I am trying to use mysql library to request my database.
I need to use the syntax with query placeholders, so I tried a simple request:
connection.query('DROP DATABASE IF EXISTS ?;', ['mydb']);
But this leads to :
'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 \'\'mydb\'\' at line 1'
The query is indeed:
'DROP DATABASE IF EXISTS \'mydb\';'
So how is this supposed to work actually ?
The MySQL notation for this is:
DROP DATABASE IF EXISTS `mydb`
Since you're escaping it as a string, that's not a database reference it can drop.
Some drivers support alternate placeholders for this very reason:
DROP DATABASE IF EXISTS ??
Normally you can't use placeholder values for things like databases, columns or tables as these are treated differently. This is a limitation of the driver.
You just need to be careful on user-supplied values and names with irregular characters in them. These need to be escaped according to MySQL schema identifier rules.
I am using Sybase Power Designer to create a database from a physical data model (Sybase creates an SQL file) . When i import the SQL file with phpMyAdmin I have the following 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 'if exists(select 1 from sys.sysforeignkey where role='FK_ARTWORK_CREATES_ARTIST'' at line 7 .
Any ideas? Could this error appear due to errors on the physical model or there is another problem?
This is the code :
if exists(select 1 from sys.sysforeignkey where role='FK_ARTWORK_HAS_BUY') then
alter table artwork
delete foreign key FK_ARTWORK_HAS_BUY
end if;
The error you are getting is from MySQL. Regardless of the tool used to generate SQL, the database seems to be MySQL (or something is terribly wrong with your systems if they are confused and think they are MySQL).
The MySQL if statement (documented here) has to be inside a stored program. That means that this code only compiles inside a stored procedure, user defined function, or trigger. It doesn't "just work" on its own.
In addition, MySQL doesn't have sys tables. It uses information_schema tables. My strongest suggestion is to use tools appropriate for your actual database. If you are using a tool to generate Sybase, then use Sybase as the destination database. If you are using MySQL, then use a tool to generate MySQL code. Or, better yet, learn how to write the commands yourself.
Finally, if you intend to use Sybase, then connect to the correct database and your problem should be fixed.
As I can't post here, and sqlfiddle.com temporary unavailable, I decided to post code with correct syntax for Sybase on the PasteBin
I am migrating a database from Sql Server 2008 to Teradata
and I am facing a problem:
In Sql Server in the ddl of a table column is defined as follows:
[rowguid] uniqueidentifier ROWGUIDCOL NOT NULL CONSTRAINT [DF_Address_rowguid] DEFAULT (NEWID())
This column uses newid() function to generate and insert random varchar value in the column [rowguid] if the user doesnt provide any input.
There is no similar function in Teradata to generate this value.
What can be used instead of of NEWID() function of Sql Server while creating similar table ddls for Teradata?
There is no native equivalent for a GUID/UUID in Teradata. Teradata does offer an IDENTITY column to provide an auto-incrementing column. The IDENTITY column does not come without its own nuances and I would encourage you to read the Chapter 5 - Create Table in the SQL Data Definition Language - Detailed Topics which has a section explaining Identity Columns.
However, as part of your migration from SQL Server to Teradata you will need to understand the concept of how data is distributed in Teradata by means of the table's primary index. This may require that you review your existing data model and re-engineer how it is physically implemented in Teradata.