varchar(max) equivilent in MySQL for T-SQL varchar(max) comparison - mysql

i have the following where clause
WHERE
(
target.sender_name <> source.sender_name
)
target aliases a table in Microsoft SQL Server while source aliases an almost identical table on a MySQL Server linked via a Linked Server
Originally i had sender_name in both tables as a text field, trying to keep the 2 tables incidental, however the query that the above clause was when, when i tried to run it spat out
The data types text and text are incompatible in the not equal to operator.
doing a bit of looking around i learned that text in tsql was depreciated and i should be using varchar(max), doing so however outputted this error
The data types varchar(max) and text are incompatible in the not equal to operator.
looking around it seems that an equivalent is VARCHAR(65535) however using that would cause problems in a table which has 4 text fields and the error i'm getting i believe would just be the same for the other 3 fields that i have in the same clause
so i am wondering if there is an equivalent to varchar(max) in mysql which i can use in my clause with a varchar(max) field in tsql
NOTE: the query that the clause is in runs in tsql, it's just the table on the linked server which is MySQL
EDIT: what the clause goes into is an UPDATE query, it checks every field and updates record in which any of the data is different, it's only ever used to sync up the 2 tables so that i can localize the work on the servers rather than using a linked server to do stuff like INNER JOINS

Related

Is there an Azure SQL Database equivalent to MySQL's "CHECKSUM TABLE", and should it be used to check if two tables are identical?

I was looking for a way to check if two tables in the same database are identical (both contents and schema), and came over this question.
The top answer for the question uses (from my understanding) a MySQL specific. When trying to run the code in an Azure SQL Database I get this error: Incorrect syntax near the keyword 'TABLE'..
Instead of using CHECKSUM TABLE to see if the two tables are identical we ended up using the two following queries:
select * from util.table1
except
select * from dbo.table2
select * from dbo.table2
except
select * from util.table1
So I essentially have three questions regarding this:
Does Azure SQL Database have an equivalent to this query?
Should we even use that query for checking if two tables are identical?
Is the option we went for (using except) a viable option? if not, why not, and what can we do better?
The CHECKSUM function in Azure SQL Database returns the checksum value computed over a table row, or over an expression list. Checksum returns the hash value over its argument list.
Example:
In the below example, the checksum value returns the computed value of the table row.
To compare the data from two tables, the best way is to use the EXCEPT.
EXCEPT returns any distinct values from the query left of the EXCEPT operator. Those values return as long the right query doesn't return those values as well.
Tables data:
With Except:

SELECT INTO Oracle SQL table from MySQL table with SQL Developer

Getting ready to get rid of a MySQL database and switch to Oracle SQL. I am using Oracle SQL Developer. Need to get the records from a MySQL table and populate its corresponding table in SQL.
I was able to establish a Database connection in SQL Developer to the MySQL database. I checked the connection by doing a simple SELECT * from the table to make sure it returned all the records.
However, the new Oracle SQL table has quite a few changes - the names in the MySQL table all had a "tn" prefix, ie tnStore, tnConfigDate, etc. The SQL table gets rid of that prefix. That is issue #1.
There will also be several new columns in the new table. That data will be added later from elsewhere. And the data will not be in the same order as the MySQL table.
How do a write up a SELECT INTO statement in SQL Developer to populate the SQL table with the data from the MySQL table and correlate the corresponding columns while leaving new fields blank for now?
Here is a way by programming but not sure how to make it in single query:
I hope we need to use data dictionary tables in oracle all_tab_columns and I am not sure in Mysql ( like similar table)
Get the column name from Mysql table by taking out prefix "tn" and
compare the column name with SQL table. (possible use an cusrsor)
If matched build SQL statement for SELECT INTO statement and blank
for new fields possibly in a loop.
Once done for all columns , execute that statement
Consider migrating the existing MySQL tables as-is straight to Oracle using SQL Developer. Then move/refactor the data around to your new-tables with desired column definitions using INSERT as SELECTs.
Could be considerably faster, plus once the 'raw' data is there, you can do your work over and over again, until you get it just right.
Note you can also simply drag-and-drop to move a MySQL table from it's connection to an existing Oracle database connection to move the table over (DDL, Data, or Both).

Querying non-unicode data in SQL Server using collation hint

I'm trying to find a way to read(select) the data from a table that has a varchar datatype. The data is in Tibetan language. When I query the data it get ???s of different lengths. Surprisingly, when I use the predicate to filter on the string, it does it successfully but the output is still ???. This means that SQL Server is able to understand the filter criteria but it's just not able to show me the output. I'm really not sure what am I missing here.
Let me share the sample here:
--create this table in database with collation set to
--Latin1_General_100_CI_AS or SQL_Latin1_General_100_CI_AS
CREATE TABLE Locations
(Place varchar(64)NOT NULL);
GO
INSERT into Locations_2(Place) VALUES ('ཡུན་རིང་འཇལ་རྒྱུ་མ་བྱུང་།')
INSERT into Locations_2(Place) VALUES ('ཁྱེད་རང་ལུང་པ་ག་ནས་ཡིམ།')
INSERT into Locations_2(Place) VALUES ('ཤོགས་པ་བདེ་ལེགས།')
GO
SELECT place collate Chinese_PRC_CI_AI from locations
where place=N'ཤོགས་པ་བདེ་ལེགས།'
This shows me nothing. But the query below shows the output as ?????????
The only difference is that I am not using N.
SELECT place collate Chinese_PRC_CI_AI from locations
where place='ཤོགས་པ་བདེ་ལེགས།'
I have inserted various Tibetan words and searched them I do get the correct search results but the output is ???????????.
Finally, it all works well when I use the datatype as nvarchar in the create table section above.
This is SQL Server 2008 SP4 on Win server 2008 R2 with latest SP.

varchar2 and number data type cause error in SQL query editor in phpmyadmin

I am trying to practice SQL and proceed to PL/SQL with the set of exercises given to me (the set of exercises is based on Oracle SQL).
I wanted to do the SQL query exercises on my laptop by starting on basics like creating tables and querying them, and I tried it before in academia, but the exercises given to me seem to be in another form and I need to learn that type of SQL query.
I used PHPMyAdmin SQL, but it seems it won't accept data type varchar2([some num]) and number([some num]) and always indicates there is an error in my syntax.
I know that this error just stems from syntax incompatibility (since I tried it in another program once, but I forgot what it was, and I am trying to learn again and master it).
So how do I get it to work? Or what other programs can I use to start to practice this form of SQL query which accepts varchar2 and number data types?
varchar2 and number are Oracle data types. MySQL's equivalents are varchar and numeric, respectively.

Conditional/Executable Comments in MySQL/SQL Server

Before I begin, I realize that what I'm attempting is bizarre and hackish. It's just for an isolated pen test, specifically SQL Injection.
What I need to do is write a SQL statement that behaves differently when executing on a MySQL database than it does when executing on a SQL Server Database.
Edit
The limitation of the Query I can build is that I can only change what's after the "WHERE id =" clause. I can't affect any other part of the query. Specifically, I need to be able to attach a " UNION SELECT * FROM some_other_table" that only gets executed by the SQL server to the end of my input.
This obviously would blow up MySQL because it doesn't have the tables I'm unioning.
Specifically:
SELECT * FROM USERS
WHERE id = My input -> (MySQL code: 'x' or 1=1 )
(MSSQL code 'x' or 1=1 UNION SELECT * FROM table)
The problem is, if either statement gets executed by the database it wasn't meant for, it blows up (and not in the way I need it to).
This lead to my discovery of Conditional/Executable Comments in MySQL.
SELECT * FROM USERS
WHERE id = /*! This will be executed but only by mysql */
That's great but I still can't prevent MySQL from executing MSSQL! I can only stop MSSQL from executing MySQL code.
My initial idea was to have a comment inside the MySQL conditional like:
SELECT * FROM USERS
WHERE id = /*! 4 or 1=1 --*/ MSSQL code that is ignored by mysql
But this throws an error saying to check my syntax at a line with nothing on it near ''.
I don't fully understand why this doesn't work but I know doesn't work with any form of MySQL comment I know of (Tried #, /*).
Is there a way to get my strange SQL statement to work? Or is there a way to do a conditional comment in MSSQL? I really just need MySQL to ignore anything after it's conditional but I have no idea how to make that happen without comments.
I'm not sure if this is what you need, but if I understand correctly you want one SQL statement that returns different results on MySQL vs. SQL Server (if that's what "behaves differently" means?). If so, one place to start would be using a system function that has the same name and syntax but different behaviour, such as SUBSTRING():
select substring('test', -1, 1)
On SQL Server that returns an empty string, but on MySQL it returns t. I don't know if using SUBSTRING() is viable in your case, but if not you may be able to find another function that's easier to use in your query.
If this doesn't help at all then I suggest you provide some more details about what limitations you have in building your query.