Good afternoon.
Can you help me, I would like to know, how the longDescription table in IBMDB2 works and how do I bring the result which is inside the columns?
Thank you.
I believe that the longDescription is one of Maximo Asset Management tables.
If so, here is an example, how to handle it in Db2 on AIX/Linux.
logon as the instance owner on the machine, such as db2inst1
Run below at command prompt to list up all databases name(s) under the instance:
$ db2 list db directory
Then run below to use one of database name(s):
$ db2 connect to DBNAME
please replace DBNAME as your target database name, such as sample.
ie. db2 connect to sample
Then run below to list up all table names in the database DBNAME
$ db2 list tables
it will list all table names and its schema name, type and creation time
Then run below to list up all columns in the table.
$ db2 describe table SCHEMA.TABLENAME
replace SCHEMA like db2inst1 and TABLENAME like longDescription
ie. db2 describe table db2inst1.longDescription
it will list up all column names and some other information
Then run below to get data from a column, such as idownertable.
$ db2 select COLOMN_NAME from SCHEMA.TABLENAME
replace COLOMN_NAME like ldownertable
ie. db2 select ldownertable from db2inst1.longDescription
If we want to see all data in the table, run below:
$ db2 select * from SCHEMA.TABLENAME
ie. db2 select * from db2inst1.longDescription
Hope this helps.
Related
I am new to Postgresql and so far I have not found a way to drop a table from specific database. To give some context:
We are doing a synchronization from Oracle to PostgreSQL of 5 tables. In postgres I have a database SoloCopy and the schema is the default public. In the Postgresql instance we have also 2 more databases SoloSynch and postgres (the default one).
What I want to do is to select SoloCopy database and:
DROP TABLE public.table1;
When I do the above DROP statement table1 is deleted only from the database that was selected when opening SQL Query. But I want to specify the database before that and to be irrelevant from where the SQL Query was open. How can I do that?
I found an answer on my own. Setup can be found here:
Psql in Task Scheduler does not run a file script
Basically I needed to use PSQL and with the connection string there I connect to a specific DB, which I can drop the tables from. The details for PGPASSWORD and the .bat file I ended up creating are in the link above. Had to start everything from CMD and switch to psql from there.
I have a AWS RDS PostgreSQL 13 server with some databases. I have to create an empty copy of one database (empty means schema (tables, views, functions) + security (users, roles)).
Is pg_dump -s what I am looking for?
Thanks!
pg_dump -d db_name -s. You will also need to do pg_dumpall -g to get the global data e.g. roles. This will get all global data for the Postgres cluster, so you may have more then you need for the particular database.
Postgres allows the use of any existing database on the server as a template when creating a new database. I'm not sure whether pgAdmin gives you the option on the create database dialog but you should be able to execute the following in a query window if it doesn't:
CREATE DATABASE newdb WITH TEMPLATE originaldb OWNER dbuser;
Still, you may get:
ERROR: source database "originaldb" is being accessed by other users
To disconnect all other users from the database, you can use this query:
SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'originaldb' AND pid <> pg_backend_pid();
For DB2 10.1 LUW, I want to create a DDL script which just contains the create table statements and then create a DDL script which just contains the constraints.
The aim is to automate the creation of the database scripts from the existing database and not rely on SQL GUIs to do this like Data Studio, SQLDbx and RazorSQL. Ideally we would like to trigger actions from the command line that can generate the create DLL for the schema, the insert data statements for each table in the schema and then generate the constraints DDL. This will help us to insert the data without dealing with the constraints which will help performance and means we will not be restricted to running the inserts in a specific order.
Unfortunately we cannot use db2move and I thought db2look would work for the DDL, but cannot find the syntax to do this. Can db2look do this or is there anything else out there that could help?
Thanks
db2look generates DDL script from existing DB and objects.
For example,
1. Getting all DDL for a DB
db2look -d <dbname> -a -e -l -x -o db2look.out
To get DDL for a table
db2look –d dbname –e –z schema_name –t Table_name -o output_file -nofed
I would like to write db2 command which find out first database exist or not and if exist that data base then drop this database and create a new updated database .
Please help for same
There is not a command or language in DB2 that support that instruction. You have to define what to do when the given name exist as an alias of a database (not the real name of the database), drop the alias? rename it?
The script will look like:
List the database directory and filter the name and the alias (db2 list db directory). Filtering can be done in linux with Awk or Grep, in Windows with Filter.
If there is a database alias with that name, then YOU decide what to do.
Instead if there is a database name with that name, then drop it (db2 drop db xxx)
Create the database.
If there is an error of existent database in the system (SQL1005N), then catalog it and drop it (db2 catalog db xxx, db2 drop db xxx)
Retry the database creation.
First query system table, in db2 for zos table SYSIBM.SYSDATABASE or SYSIBM.SYSTABLES, in db2 LUW version table SYSCAT.tables . If there are rows in query, database exists.
In LUW, you can do:
--#SET TERMINATOR #
BEGIN
DECLARE TABLE_NOT_FOUND CONDITION FOR SQLSTATE '42704';
DECLARE CONTINUE HANDLER FOR TABLE_NOT_FOUND;
EXECUTE IMMEDIATE 'DROP TABLE myschema.mytable';
END #
You can convert this snippet into a function that receives the schema name and table name.
calling this function will let you drop the table if exist:
CALL FNC.DROP_IF_EXISTS('TABLENAME')!
I am very new to Postgres and the main problem I have now is that I don't have an overview of my server. If you use something like pgadmin3 it's easy to browse and to get a general idea of the structure of the database.
So looking for some general commands that could help me discover my database server.
Very basic commands:
Connect to database with client console
psql dbname
Dump db tables
\d
Dump a table schema
\d table
List table content
select * from table
General help
\?
Source/Further info: https://www.postgresql.org/docs/current/static/app-psql.html