CREATE TABLE LIKE in DB2 10 for z/OS throwing an error - db2

Using DB2 for z/OS v.10, I'm getting an error when I specify a tablespace when using CREATE TABLE ... LIKE.
I can successfully use CREATE TABLE ... LIKE if I don't specify a new tablespace, but it throws an error when I specify a tablespace. The manual seems to say that this should work, but I must have an error in the syntax.
Create Table MySchema.Deleteme2
Like MySchema.Deleteme;
Table MYSCHEMA.DELETEME2 created.
Create Table MySchema.Deleteme2
Like MySchema.Deleteme
in MYDB.SOMETS
;
THE STATEMENT COULD NOT BE PROCESSED BECAUSE ONE OR MORE IMPLICITLY CREATED OBJECTS ARE INVOLVED 1.
Any ideas?
Thank you for your help!
Dave

Resolved by ensuring that the target tablespace was first created with the correct attributes and permissions, before running the create table .... like ... in ...

Related

Unable to create a table in new database

beginner at SQL here, specifically using PostgreSQL. I'm trying to do something for a class here, but I keep receiving an error message and I'm not sure why. I've created a new database called "games", and I'm trying to create a basic table. The code is below.
The error message I receive is, [0A000] ERROR: cross-database references are not implemented: "games.games_schema.player_data" Position: 14
I can make the table in the default DB with postgreSQL fine, but why am I having issues trying to specifically create this table within this new Database?
CREATE DATABASE games;
CREATE TABLE games.games_schema.Player_Data
(Player_ID int,
Player_Name VARCHAR(255),
Player_System VARCHAR(255));
I thought the way I have my create table statement set up, is telling the server to create a table at that location. (database --> DBschema --> table)
Thanks for any help.
You created the games database, but that does not create a games_schema within it. It'll only create the schema Public (unless the default template has been modified) The solution is to either create a "games_schema" in the "games" database, or create your DB objects in the public schema.
Option 1: Create a schema.
create schema games_schema;
create table games_schema.player_data( ... );
Option 2: Use the Public schema.
create table player_data( ... );
My choice would be option 1, as I never allow anything other than extensions and Postgres supplied objects in public.

Issue with basic create statements in postgreSQL

I've used the psql module to create a new database using the following syntax:
CREATE DATABASE fish
I can open the database. However, when I try to create tables or columns it gives me a syntax error for the following message.
CREATE TABLE salmon;
this is the error message:
ERROR: syntax error at or near ";"
LINE 1: CREATE TABLE species;
I've checked a lot of online postgreSQL resources and they haven't been of much help. To the best of my knowledge, I haven't messed up the syntax. Thanks.
you can use this syntax for empty table:
create table salmon();
You must create atleast one column in a table:
CREATE TABLE salmon ( column_name data_type ...........);
Postgres create table link: https://www.postgresql.org/docs/9.1/static/sql-createtable.html
You can't create an empty table - it must have at least one column. E.g.:
CREATE TABLE salmon (name VARCHAR(10));
psql is not a module. Please read https://www.postgresql.org/docs/current/static/app-psql.html
you odn't open a database - you connect to it.
Establishes a new connection to a PostgreSQL server
https://www.postgresql.org/docs/current/static/sql-createtable.html
{ column_name | ( expression ) }
Either column list (create table a (a int);) or expression (create table b as select now() time_column) is obligatory part.

How can I check if tablespace exist in DB2 z/os

How can I check if tablespace exist in DB2 z/os.
I have to create table RMPOLICY
My task is create script for update database. Update will create table and auxiliary table.
For that task I have to make 4 steps:
1. create tablespace for table
2. create tablespace for auxiliary table
3. create table
4. create auxiliary table
I will be great if I can check all this step for completed before. It posible to check if table exist with
SELECT COUNT(*) INTO V_ALREADY_EXIST FROM SYSCAT.TABLES WHERE UPPER(RTRIM(TABNAME)) = UPPER(RTRIM('RMPOLICY'));
But I don't know how to check if tablespace exist.
Can you please help to determin this information from script?
It sounds like you're looking for SYSIBM.SYSTABLESPACE.

Do not have select privilege for temporary table in db2 stored procedure

I am running a stored procedure in DB2 10.1 which creates a created global temporary table and it returns the following error message that seems to say that it cannot select from the temporary table that it has just created in the same stored procedure
"USER" does not have the required authorization or privilege to
perform operation "SELECT" on object "MYSCHEMA.MYTABLE"..
SQLCODE=-551, SQLSTATE=42501, DRIVER=4.16.53
I have not encountered this problem with the other stored procedures and they create temp tables in the same way. The user privileges are controlled by groups, but due to issues with the groups I have started to give privileges to the users directly.
I cannot grant select permissions to the temp table because its not yet created and not sure how to fix this situation.
Has anyone come across this problem before and if so how did you fix it?
Thanks for any help.

how can I rename a table / move to a different schema in sql DB2?

I am trying to rename a table in db2 like so
rename table schema1.mytable to schema2.mytable
but getting the following error message:
the name "mytable" has the wrong number of qualifiers.. SQLCODE=-108,SQLSTATE=42601
what is the problem here.... I am using the exact syntax from IBM publib documentation.
You cannot change the schema of a given object. You have to recreate it.
There are severals ways to do that:
If you have only one table, you can export and import/load the table. If you use the IDX format, the DDL will be included in the generated file. If using another format, the table has be created.
You can recreate the table by using:
Create table schema2.mytable like schema1.mytable
You can extract the DDL with the db2look tool
If you are changing the schema name for a schema given, you can use ADMIN_COPY_SCHEMA
These last two options only create the table structure, and you still need to import the data. After having create the table, you insert the data by different ways:
Inserting directly
insert into schema2.mytable select * from schema1.mytable
Via load from cursor
Via a Load or import from file (The file exported in the previous step)
The problem is the foreign relations, because they have to be recreated.
Finally, you can create an alias. It is easier, and you do not have to deal with relations.
You can easily rename a table with this statement:
RENAME TABLE SCHEMA.TABLENAME TO NEWTABLENAME;
You're not renaming table in provided example, you're trying to move to different schema, it's not the same thing. Look into db2move tool for this.
if you want to rename a table in the same schema, you can use like this.
RENAME TABLE schema.table_name TO "new_table_name";
Otherwise, you can use tools like DBeaver to rename or copy tables in a db2 db.
What if you leave it as is and create an alias with the new name and schema.
Renaming a table means to rename a table within same schema .To rename in other schema ,db2 call its ALIAS:
db2 create alias for