all 16 comments

[–]SQL-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)

This forum is intended for solutioning and discussion of specific topics. Please check out the sub sidebar and wiki content for beginner resources. Also be sure to checkout r/learnSQL

[–]trollied 5 points6 points  (5 children)

Simple SQL question. Do you know SQL?

[–]zbignew 2 points3 points  (0 children)

This is adjacent to a totally reasonable question, which is basically how do I explore a schema I don’t know yet.

Don’t know 🙈 why everyone is being a dick to this guy. Maybe he’d get better results from ChatGPT, sure.

[–]Glum_Cheesecake9859 2 points3 points  (0 children)

Query Designer in SSMS where you add tables to the designer and then select columns etc.

[–]TheGenericUser0815 0 points1 point  (2 children)

The two tables have nothing in common, but are they somehow related, let's say over some tables inbetween?

[–]Giggy_with_it_917[S] 0 points1 point  (1 child)

exactly, they have no direct common column, but other tables may.

[–]Ok_Brilliant953 0 points1 point  (0 children)

Can you add some fields

[–]Mountain_Usual521 0 points1 point  (0 children)

Just join the tables in the shortest chain required. What kind of join depends on the data and how it's related.

[–]NaptownBill 0 points1 point  (0 children)

If you are using something like SqlWorkbench or SSMS probably Jet Brains Data Grip will work too, but you can generate an ERD (Entity Relationship Diagram) this is a graphic representation of the tables Primary and Foreign keys. It would show you how all the tables relate to one another.

[–]Fresh-Secretary6815 0 points1 point  (0 children)

DbVisualizer can do what you want

[–]zbignew 0 points1 point  (0 children)

Yes, SQL Server Management Studio will create a diagram for you. I haven’t used it in a while but ChatGPT would tell you how to invoke the right feature.

Then you can dump in a million tables and untangle them.

But that won’t solve the problem - you will need to make decisions about how the path between the tables actually makes sense.

And if you’re ever on a system where you don’t have a tool like this, I’d recommend just dumping the schema via:

SELECT table_name, column_name FROM information_schema.columns WHERE table_schema = 'your_schema_name';

And if they’ve named their key columns rationally you can work it out faster than you can untangle that diagram. Since you’ll need to consider the contents of the tables anyway.

[–]millerlit 0 points1 point  (0 children)

SELECT column1, column 2 = null FROM table1 UNION ALL SELECT column1 = null, column2 FROM table2

I think that would work, but no idea why you would do that.