Does anyone know how to retrieve UUID via HSQLDB.
For example when i try
SELECT UUID();
via MYSQL it works fine. But the same statement doesn't work with HSQLDB.
The following methods achieve the corresponding purpose
VALUES (UUID())
CALL(UUID())
SELECT UUID() FROM (VALUES(0)) t;
Is there a way which is same for mysql and hsqldb?
HSQL doc says that UUID has been activated. http://hsqldb.org/doc/guide/builtinfunctions-chapt.html
Thanks.
Turn on the MySQL compatibility mode in HSQLDB and it will allow your SELECT statement:
http://hsqldb.org/doc/2.0/guide/compatibility-chapt.html#coc_compatibility_mysql
Is there a way which is same for mysql and hsqldb?
Only way i can think off.
Create a table DUAL in HSQLDB
CREATE TABLE DUAL (
id INT
);
So you can use
SELECT UUID() FROM DUAL LIMIT 1;
Then the query should work the same in both MySQL and HSQLDB.
DUAL in MySQL is a non existing dummy table.
Related
I wanted to check whether a table exists before deleting the values inside the table. In SQL Server we can do as simple as so :
IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'table_to_be_edited')
BEGIN
DELETE FROM table_to_be_edited;
END;
but how do we do it in MySQL ?
I am using MySQL Workbench V8.0.
When delete an option is to ignore the table not found error. This eliminates race conditions where a table is created between the test and the truncate. Always consider this when doing SQL operations.
So, primarily I work in oracle and have gotten spoiled by working with dual. For a user with select privileges on a given database how could you reproduce the dual functionality?
IE:
Select 'foo' from dual
Probably a very simple answer that I'm just missing.
I remember using Select 1 from dual in oracle and just select 1; in mysql. So I think you just try without a table reference.
This was to verify connectivity so not sure if it applies in your case.
You are permitted to specify DUAL as a dummy table name in situations where no tables are referenced:
SELECT 1+1;
OR
SELECT 1 + 1 FROM DUAL;
In most cases you can just omit FROM DUAL in MySQL and MariaDB.
But if you need a WHERE to verify things, you still need the FROM DUAL.
Example (usage: one way to avoid re-inserting with different id):
INSERT INTO `t1`(`id`, `name`, `description`)
SELECT NULL, 'LopsusNonsus', 'my description'
FROM DUAL
WHERE NOT EXISTS (SELECT id FROM `t1` WHERE `name`='LopsusNonsus' LIMIT 1) ;
You can use information_schema.schemata table for the current session database as it has one row for each database.
select
1
from
information_schema.schemata
where
schema_name = database()
Is it necessary to define the new table definition before using SELECT INTO query in MYSQL.
I am getting problem to execute the query when I writ e like:
SELECT *
INTO newtable
FROM oldtable
WHERE 1=0;
the error showing is:
Undeclared variabie: newtable
if you have newtable
try :
INSERT INTO newtable SELECT ...
if you don't have newtable
try :
CREATE TABLE newtable AS SELECT ...
The MySQL manual search engine is terrible but googling for something like mysql 5.5 select into will normally take you to the right page:
MySQL Server doesn't support the SELECT ... INTO TABLE Sybase SQL
extension. Instead, MySQL Server supports the INSERT INTO ... SELECT
standard SQL syntax, which is basically the same thing.
If you read the documentation here it says:
With INSERT ... SELECT, you can quickly insert many rows into a table from one or many tables
So, yes, you need to create the new table first.
You can use CREATE TABLE new LIKE old to create a new, empty table, which is a copy of the original table structure.
in mysql i can create a table named "select" using the following statement
CREATE TABLE `SELECT` (
Id INT,
Name VARCHAR(255)
}
and it executed successfully and the table is created by the name "select" as you can see the image above. But the same couldn't be done in oracle 11g.
What would be the sql query that's required to create a table named "select" in other sql databases
I think you should use
CREATE TABLE "SELECT" ...
use dumme
create table [select]
(
i int
)
select * from [select]
i dont know why you in such need to create table with reserve word but in MS SQL server 2005 you can use the above statment to create a table with name select
Select is a reserved word, and tgus should actually not be used. The validation in mysql is just a little less strict.
Try using another name, like selectTable or selectId
I want to confirm whether there is a certain table.
When create a table, there is an SQL sentence such as DROP TABLE IF EXISTS xxx_tb.
Will there be the method that can identify the existence of the table by SQL likewise?
Use INFORMATION_SCHEMA:
select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'MyTable';
Should be portable across most databases.
You want the SHOW TABLES command of MySQL:
SHOW TABLES LIKE 'xxx_tb';
Or indeed, you can just do a query like
SELECT COUNT(*) FROM tbl WHERE 1=0
Which will give an error (see documentation for exact error code, or try it) if the table doesn't exist, but succeed with no results if it does.