how to import text to lucidchart entity relationship diagram - lucidchart

I have extensive amount of csv files and i parsed and get a filenames and column names to import any ER diagram tool. But when lucidchar expect query result. If i have example outcome of query to import entity relationship. I can arrange my format according to that and import to the lucidchart. Anyone has a expected format

You insert the output of your query, for example if you use MySQL
SELECT 'mysql' dbms,t.TABLE_SCHEMA,t.TABLE_NAME,c.COLUMN_NAME,c.ORDINAL_POSITION,c.DATA_TYPE,c.CHARACTER_MAXIMUM_LENGTH,n.CONSTRAINT_TYPE,k.REFERENCED_TABLE_SCHEMA,k.REFERENCED_TABLE_NAME,k.REFERENCED_COLUMN_NAME FROM INFORMATION_SCHEMA.TABLES t LEFT JOIN INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_SCHEMA=c.TABLE_SCHEMA AND t.TABLE_NAME=c.TABLE_NAME LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE k ON c.TABLE_SCHEMA=k.TABLE_SCHEMA AND c.TABLE_NAME=k.TABLE_NAME AND c.COLUMN_NAME=k.COLUMN_NAME LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS n ON k.CONSTRAINT_SCHEMA=n.CONSTRAINT_SCHEMA AND k.CONSTRAINT_NAME=n.CONSTRAINT_NAME AND k.TABLE_SCHEMA=n.TABLE_SCHEMA AND k.TABLE_NAME=n.TABLE_NAME WHERE t.TABLE_TYPE='BASE TABLE' AND t.TABLE_SCHEMA NOT IN('INFORMATION_SCHEMA','mysql');

Related

Determine the sequences related to a given table name PostgresSQL

I am trying to write a function to determine the sequences related to a given table name, in the query within the function, I went with something like this:
select s.relname as sec from pg_class s
join pg_depend d on d.objid=s.oid and d.classid='pg_class'::regclass
and d.refclassid='pg_class'::regclass
join pg_class t on t.oid=d.refobjid
join pg_namespace n on n.oid=t.relnamespace
join pg_attribute a on a.attrelid=t.oid and a.attnum=d.refobjsubid
where s.relkind='S' and t.relname = 'table_name'
However it doesn't seem to find all the sequences that exists, i.e. for some tables, it just doesn't find the related sequences, but for certain ones it does.

Left join results in cross join in spark

I am trying to join two tables in pyspark using a SQLContext:
create table joined_table stored
as orc
as
SELECT A.*,
B.*
FROM TABLEA AS A
LEFT JOIN TABLEB AS B ON 1=1
where lower(A.varA) LIKE concat('%',lower(B.varB),'%')
AND (B.varC = 0 OR (lower(A.varA) = lower(B.varB)));
But I get the following error:
AnalysisException: u'Detected cartesian product for LEFT OUTER join between logical plans
parquet\nJoin condition is missing or trivial.\nUse the CROSS JOIN syntax to allow cartesian products between these relations.;
Edit:
I solved the problem using the following in Spark:
conf.set('spark.sql.crossJoin.enabled', 'true')
This enables the cross join in Pyspark!
I cannot see the on clause condition with your left join.. A Left join without join condition will always results in cross join. A cross join will repeat each row of your left hand table for each row the table on your right side. Can you edit your query and include the 'ON' clause with your join key column.

MS SQLServer Searching to see if a value is contained in other values

I come from a background in PostgreSQL.
If I wanted to search all of the columns in all of the tables for any column name that contained "the" somewhere in the value, I would do this:
select *
from information_schema.columns
where column_name ilike '%the%'
This does not work in SQL Server 2008 R2, does anyone have any suggestions? I am running this query so far:
select t.name as table_name, c.name as column_name
from sys.tables as t
inner join
sys.all_columns as c
on
c.object_id = t.object_id
where t.name ilike '%the%'
order by c.name, t.name;
The where t.name ilike '%the%' is what makes the query fail with the following error message:
An expression of non-boolean type specified in a context where a
condition is expected, near 'ilike'.
Does anyone have any suggestions?
Thank you
ilike doesn't exist in sql server, you can use like instead.

How to take an intermediate data for the complex sql query. Postgresql

I have some complex queries to the postgresql which takes data from several tables joined each other with outer left join operators.
I need to test these queries so I need a fixtures for the tests contain only data I need, not whole tables data.
How could I see the intermediate results for these join subqueries to use it as a fixtures?
For example, I have tables A, B and C and query
SELECT A.column
FROM A
LEFT JOIN B ON A.b_id = B.id
LEFT JOIN C ON A.c_id = C.a_id
How could I take a result as "From table a: {part of A table taking part on query}, From table B {part of B table taking part on query}" etc, when parts of tables shows needed data or something like this. Is there any existing tool or method for it?
Unfortunately, EXPLAIN and ANALYSE shows only statistics and benchmarks, not data.
maybe you mean
SELECT A.*
FROM A
LEFT JOIN B ON A.b_id = B.id
LEFT JOIN C ON A.c_id = C.a_id
limit 10
to see what's happening in A from the join?
Or perhaps
select concat('from table a', a.col1, a.col2...) ,
concat('from table b', b.col1, b.col2...)
from ...
String functions such as concat: http://www.postgresql.org/docs/9.1/static/functions-string.html
also worth looking into http://www.postgresql.org/docs/9.1/static/functions-array.html at array_append()

Crystal Reports: expressions in table joining

Is it possible to join tables in Crystal Records by using not simple and usual field A = field B but something more complex like:
select * from table1 inner join table2
on table1.A=2*table2.B
or
select * from table1 inner join table2
on ASCII(table1.A)=ASCII(table2.B)
Use a single Command instead of tables in the Database Expert. You will be able to use more-complex SQL.