A query with all types of constraints used in oracle SQL 10g? - oracle10g

I am unable to write a query in oracle SQL 10_g which uses all types of constraints using employees and departments tables.
Can you help me with the same?

Do you mean:
select * from all_constraints
where table_name in ('EMPLOYEES', 'DEPARTMENTS');

Related

What if PostgreSql introduce a new function with name "cypher" then how to distingush between cypher and sql query with cypher function

Currently, the structure of Apache-age query is:
SELECT * FROM cypher(<graph_name>, <cypher_query>)
I am not sure how PostgreSQL is able to distinguish between regular sql queries and Cypher queries after loading age extension.
For now parsers can differentiate between cypher query and normal SQL queries by looking at cypher function in the from clause of select statement. [We are using this approach to distinguish between cypher and normal queries]
But I was concerned that if PostgreSql introduce a new function with the name "cypher" for some functionality, let's say that cypher function can be used in from-clause like we use generate_series in from-clause in the following example.
SELECT * FROM generate_series(1, 10) AS number;
Then there will be conflict in between. How can we resolve that in development?
If PostgreSQL introduces a new system function, that function will be in the system schema pg_catalog. You can disambiguate between such a function and your function by qualifying the function name with the schema, for example
SELECT myschema.cypher(...);

Is there any way to list all the views related to a table in the existing postgres schema

I got a Postgres database with multiple schemas. I'm trying to optimise my database tables with optimal data types. more often I end with the error
cannot alter the type of a column used by a view
while using the query alter table schema.tbl_name alter column column_name type varchar(5) using column_name::varchar(5);
Is there any way (function) that I could list all the views related to the table?
Use this query:
select
u.view_schema schema_name,
u.view_name,
u.table_schema referenced_table_schema,
u.table_name referenced_table_name,
v.view_definition
from information_schema.view_table_usage u
join information_schema.views v on u.view_schema = v.table_schema
and u.view_name = v.table_name
where u.table_schema not in ('information_schema', 'pg_catalog')
order by u.view_schema, u.view_name
Credit: Dataedo.com's article List tables used by a view in PostgreSQL database

Use criteria or query dsl to find all tables names in a given schema

Is there a way to find all table names that begin with t_ in a given schema name with criteria API or query DSL( or even database metadata)? If it exists, could you please show me how I can do it using a schema name or view? I'm using PostgreSQL for the database.
I don't want to use a native query.
yes, you can use below query:
SELECT table_catalog,table_schema,table_name
FROM information_schema.tables
WHERE table_name LIKE 't\_%'
AND table_type='BASE TABLE' -- to filter out Tables only, remove if you need to see views as well

Getting a Result Set's Column Names via T-SQL

Is there a way to get the column names that an arbitrary query will return using just T-SQL that works with pre-2012 versions of Microsoft SQL Server?
What Doesn't Work:
sys.columns and INFORMATION_SCHEMA.COLUMNS work great for obtaining the column list for tables or views but don't work with arbitrary queries.
sys.dm_exec_describe_first_result would be perfect except that this management function was added in SQL Server 2012. What I'm writing needs to be backwards compatible to SQL Server 2005.
A custom CLR function could easily provide this information but introduces deployment complexities on the server side. I'd rather not go this route.
Any ideas?
So long as the arbitrary query qualifies to be used as a nested query (i.e. no CTEs, unique column names, etc.), this can be achieved by loading the query's metadata into a temp table, then retrieving column details via sys.tables:
SELECT TOP 0 * INTO #t FROM (query goes here) q
SELECT name FROM tempdb.sys.columns WHERE object_id = OBJECT_ID('tempdb..#t')
DROP TABLE #t
Thanks to #MartinSmith's for suggesting this approach!

How to fetch column names of a table using HQL and populate in a list?

I want to fetch column names of a table using HQL and populate the same in a list?..Please guide. I am using IBM DB2 database.
I have not tested, but you can query the DB2 catalog in order to get the metadata. If you execute the equivalent in HQL, it should work
select colname
from syscat.columns
where tabschema like 'MYSCHEMA%' and tabname = 'MYTABLE'
order by colno