SQL Server Tip Thread: Using INFORMATION_SCHEMA

INFORMATION_SCHEMA lets you query tables, columns, and other metadata about your database. Knowing how to use it, and how to further leverage it to create SQL statements dynamically, can make you a more efficient SQL developer.
If you want to view this thread as an expanded blog post, you can also go check it out at:

apop.tech/posts/searchin…

I go into detail there about how I combined INFORMATION_SCHEMA with SQL cursors, dynamic SQL, and a temporary table to find data across 20+ different tables.
As a basic example, if you need to search across a large number of tables for one or more values, and the tables have a common pattern in their name, you can query INFORMATION_SCHEMA to find all of the tables you need to search.
This example searches across all tables in the CORE database to find tables that contain USER_CORE in the table name:
Here's the full Microsoft documentation on INFORMATION_SCHEMA for reference:

docs.microsoft.com/en-us/sql/rela…
If you found this thread helpful, please consider liking and retweeting the original tweet, and follow me for more content about SQL and data!
Excellent point here from @nilsandrey - INFORMATION_SCHEMA will only return metadata that your user has permission to access:

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Alex Popoutsis

Alex Popoutsis Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @apopoutsis

12 Oct
SQL Resources for Beginners 🧵

I've had people ask me about good places to start when learning SQL. I mainly learned in a classroom setting in college and then additional on-the-job and just-in-time training. So I did some searching to try and find some beginner resources.
DataCamp has a four-hour, free introduction to SQL basics:

datacamp.com/courses/introd…
FreeCodeCamp also has a free, full course on SQL and databases.

freecodecamp.org/news/sql-and-d…
Read 7 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(