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

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.

Related

postgres: alter publication with IF EXISTS

I have a SQL ALTER statement to update an existing publication to add a table.
ALTER PUBLICATION publication_p1 ADD TABLE schema.tablename;
I want to add this line to an automated database versioning script. However I want to see if the publication would be added IF the table wasn't a member AND if the publication existed. So something like:
ALTER PUBLICATION IF EXISTS publication_p1 ADD TABLE IF NOT EXISTS schema.tablename;
I tried my idea, and obviously didn't work. Looking at the postgres documentation IF EXISTS is not supported.
Is there a way of applying something similar in POSTGRES?
Thanks

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

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 ...

Rename column on iSeries DB2

I would like to rename a column in DB2 on the iSeries platform. The link below is related, however, I do not have a primary key or constraint defined on the columns I would like to rename. In addition, I'm not certain that they are on the iSeries as well.
Rename column in DB2
However, I decided to give it a go with the following statement:
ALTER TABLE MYLIB.MYFILE RENAME COLUMN COL0001 TO COL0002;
Post execution, I am given the following warning:
Additionally, I do not see a RENAME COLUMN in the docs:
https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_71/db2/rbafzatabl.htm
Is this something that is not possible on V7R1 DB2?
There is no RENAME COLUMN clause in the ALTER TABLE statement in DB2 for IBM i.
You may probably achieve the same with the following:
ALTER TABLE MYLIB.MYFILE ADD COLUMN COL0002 ...;
UPDATE MYLIB.MYFILE SET COL0002 = COL0001;
ALTER TABLE MYLIB.MYFILE DROP COLUMN COL0001;

Delete column in hive table

I am working with hive version 0.9 and I need delete columns of a hive table. I have searched in several manuals of hive commands but I only I have found commands to version 0.14. Is possible to delete a column of a hive table in hive version 0.9? What is the command?
Thanks.
We can’t simply drop a table column from a hive table using the below statement like sql.
ALTER TABLE tbl_name drop column column_name ---- it will not work.
So there is a shortcut to drop columns from a hive table.
Let’s say we have a hive table.
From this table I want to drop the column Dob. You can use the ALTER TABLE REPLACE statement to drop a column.
ALTER TABLE test_tbl REPLACE COLUMNS(ID STRING,NAME STRING,AGE STRING); you have to give the column names which you want to keep in the table
There isn't a drop column or delete column in Hive.
A SELECT statement can take regex-based column specification in Hive releases prior to 0.13.0, or in 0.13.0 and later releases if the configuration property hive.support.quoted.identifiers is set to none.
That being said you could create a new table or view using the following:
drop table if exists database.table_name;
create table if not exists database.table_name as
select `(column_to_remove_1|...|column_to_remove_N)?+.+`
from database.some_table
where
...
;
This will create a table that has all the columns from some_table except the columns named column_to_remove_1, ... , to column_to_remove_N. You can also choose to create a view instead.
ALTER TABLE table_name REPLACE COLUMNS ( c1 int, c2 String);
NOTE: eliminate column from column list. It will keep matched columns and removed unmentioned columns from table schema.
we can not delete column from hive table . But droping a table(if its external) in hive and the recreating table(with column excluded) ,wont delete ur data .
so what can u do is(if u dont have table structure) run this command :
show create table database_name.table_name;
Then you can copy it and edit it (with column eliminated).Afterwards you can do as per invoke the shell
table details are empid,name,dept,salary ,address. i want remove address column. Just write REPLACE COLUMNS like below query
jdbc:hive2://> alter table employee replace columns(empid int, name string,dept string,salary int);
As mentioned before, you can't drop table using an alter statement.
Alter - replace is not guaranteed to work in all the cases.
I found the best answer for this here:
https://stackoverflow.com/a/48921280/4385453

Where will the tablespace be stored?

I am creating a table with tablespace:
CREATE TABLE SALARY.....
IN ACCOUNTING INDEX IN ACCOUNT_IDX
Where will the Accounting and Account_IDX be created?
The script that you have above will create SALARY in the ACCOUNTING tablespace, with indexes for that table in ACCOUNT_IDX tablespace.
The ACCOUNTING and ACCOUNT_IDX tablespaces need to be created in a separate script that has CREATE TABLESPACE statements.
If you look at the syntax for CREATE TABLESPACE, the USING part of the statement will tell DB2 where to put the files for the tablespace.
DB2 Create Tablespace Reference