Why is my table name not valid? - sql

Here is the create statement:
create table dbmonitor.DBMON_DATABASE_TYPE (
DATABASE_TYPE_ID BIGINT IDENTITY NOT NULL,
DispName NVARCHAR(255) null,
primary key (DATABASE_TYPE_ID)
)
and this is the error I get:
13:40:57,685 ERROR [TestRunnerThread] SchemaExport [(null)]- The table name is not valid. [ Token line number (if known) = 1,Token line offset (if known) = 24,Table name = DBMON_DATABASE_TYPE ]
The table name is not valid. [ Token line number (if known) = 1,Token line offset (if known) = 24,Table name = DBMON_DATABASE_TYPE ]

Possibilities:
Is dbmonitor the name of your database? You can't put a . in a table name.
Do you mean CREATE TABLE dbmonitor.dbo.DBMON_DATABASE_TYPE?
Did you try CREATE TABLE DBMON_DATABASE_TYPE?

I'm not sure if dbmonitor is meant to be a schema name, but according to the documentation for the SQL CE CREATE TABLE statement, you cannot include a schema name with the table name.
Contrast this for SQL Server 2005 Compact Edition (just showing the initial part of the statement),
CREATE TABLE table_name
( { < column_definition > | < table_constraint > } [ ,...n ]
)
with this for SQL Server 2008:
CREATE TABLE
[ database_name . [ schema_name ] . | schema_name . ] table_name

This may not be exactly an answer for this question's criteria , but for those who might get here :
this error can also happen when you try to use EntityFramework.Extended library with Sql Server CE. It seems that they are not compatible.
check these links :
https://github.com/loresoft/EntityFramework.Extended/issues/35
https://github.com/loresoft/EntityFramework.Extended/issues/11

Related

convert varchar[ ] column type to uuid[ ]

there is a column of type character varying[] , which contains data of type uuid like
{0f071799-e37e-4e1c-9620-e580447416fe,913a7134-6092-45fa-ae18-163302db8112},
but there are also some old values of another type like {5edfd4edfa1bb21a142442a0}.
How can the column type be converted?
I used the script:
alter table services alter column office_ids type uuid[] USING office_ids::uuid[];
but gives an error - invalid syntax for type uuid: "5edfd4edfa1bb21a142442a0".
You must first convert your 25 character values into valid uuid values.
One such conversion would be:
8f5f7cc46821423fa6057025a -> 00000008-f5f7-cc46-8214-23fa6057025a
The SQL for this is:
regexp_replace('8f5f7cc46821423fa6057025a', '^(.)(.{4})(.{4})(.{4})(.{12})^', '0000000\1-\2-\3-\4-\5')
output:
00000008-f5f7-cc46-8214-23fa6057025a
Which leaves valid uuids unchanged. See live demo.
You can use this to update the bad values like this:
update services set office_ids = array(
select regexp_replace(t.val, '^(.)(.{4})(.{4})(.{4})(.{12})$', '0000000\1-\2-\3-\4-\5')
from unnest(services.office_ids) as t(val)
)
Then your alter command will work.
See live demo.

Unable to create a table in SQL

I am trying to execute this simple query.
create Table test1
{
ID int identity(1,1),
value nvarchar
}
Its throwing an error as
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '{'
I am stuck here. Please help me out of this
Use () instead of {}
create Table test1
(
ID int identity(1,1),
value nvarchar
)
don't use follow brace. you should use parenthesis.
create Table test1
(
ID int identity(1,1),
value nvarchar
)
Syntax for create table:
CREATE TABLE table_name
(
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size),
....
);
Use parenthesis ( ) instead of curly braces { }
Set data size for the nvarchar. other wise when insert any string value more than 1 character you will receive String or binary data would be truncated. error
Not mandatory but adding NOT NULL to the IDENTITY column is good practice.
Adding schema name to the table is good practice. (By default dbo is the schema)
So the working query will be:
create Table dbo.test1
(
ID int identity (1, 1) NOT NULL,
value nvarchar (500)
)
Use () instead of {}
Check out this link for the example SQL Create Table
On the internet about the topic you will find many useful information.

really simple sybase sql function won't work

I was wondering why this simple sql function won't work?
CREATE FUNCTION dbo.getTableCounts (#STREAM_ID nvarchar(10))
RETURNS table
AS RETURN ( select 1 as 'one', 2 as 'two');
When I run it in qwerybuilder I get two error messages:
Incorrect syntax near the keyword 'table' (for line 2)
and
Incorrect syntax near ',' (for line 3)
I don't understand how this is incorrect syntax. Does anyone see why this is an error?
According to ASE's Reference manual You can only return a scalar expression:
create function [ owner_name. ] function_name
[ ( #parameter_name [as] parameter_datatype [ = default ]
[ ,...n ] ) ]
returns return_datatype
[ with recompile]
as
[begin]
function_body
return scalar_expression
[end]
So you can't use table as data type.
Unlike Microsoft SQL Server, in Sybase if you need table as a result type you don't use a function but a stored procedure. In your case the definition of the procedure (written in Watcom-SQL) will look like:
CREATE PROCEDURE getTableCounts(#STREAM_ID NVARCHAR(10))
RESULT(one INT, two INT)
BEGIN
SELECT 1 AS one, 2 AS two;
END;
However this option is not supported by Transact-SQL dialect in Sybase.

Update Table with Hibernate Problem

I'm not able to update a table with Hibernate.
The table is created with the following statement and stored in a PostgreSQL Database.
CREATE TABLE staat
(
sta_id serial NOT NULL, -- ID des Staates
sta_bezeichnung character varying(50) NOT NULL, -- Langbezeichnung
sta_lkz character varying(10) NOT NULL, -- Laenderkennzeichen
sta_vorwahl character varying(10), -- Telefon Landesvorwahl
sta_eu boolean DEFAULT false, -- Ist der Staaat ein EU-Mitglied?
CONSTRAINT staat_pkey PRIMARY KEY (sta_id),
CONSTRAINT staat_sta_bezeichnung_key UNIQUE (sta_bezeichnung)
)
WITH (
OIDS=FALSE
);
Rights are set correct, because select, insert and update are possible with a SQL Manager. The following update statement also works with the SQL Manager.
But now the problem: when I want to update the table with my application, it generates PSQLException with the following output:
WARNUNG: SQL Error: 0, SQLState: 22004 and ERROR: query string argument of EXECUTE is null
The source code:
Query q = s.createQuery("Update Staat set sta_bezeichnung = 'BlaBla' where sta_id = 1");
int status = q.executeUpdate();
I think the problem has something to do with NOT NULL columns, because tables without NOT NULL columns can be updated with the same source code...
Does anyone has an idea of what is wrong or what I have to do???
Edit: tried with SQL (q.executeSQLUpdate) and HQL
Transaction tr = s.beginTransaction();
staat = (Staat)s.get(Staat.class, new Integer(0));
staat.setStaBezeichnung("BlaBla");
s.update(staat);
tr.commit();
Generates followin error: ERROR: query string argument of EXECUTE is null and Could not synchronize database state with session
Edit2: update works fine without hibernate
Please check your Hibernate mapping file for Staat maybe you have not configured a not-null constraint for some attribute/field, which is not-null in database.
It looks like you are trying to use SQL query where HQL query is expected. Try
Query q = s.createSQLQuery(....);
Or better yet, use mapped classes with HQL. But I don't know your mapped classes, so can't speculate on specifics.

move a function to another schema

It is possible to move a table from one schema to another:
ALTER TABLE my_table SET SCHEMA different_schema;
However, I cannot find the equivalent feature for moving a function from one schema to another.
How can I do this?
(version 8.3+)
Taken from the docs:
ALTER FUNCTION name ( [ [ argmode ] [ argname ] argtype [, ...] ] )
SET SCHEMA new_schema