Query to show foreign keys for specified table and or column
Category: SQL Page 1 of 3
Where is it? WHERE IS IT? WHERE????
Sometimes you need to search for a value in the table, but you have no idea where it is. The query will use a cursor allowing you to search through multiple tables and multiple columns to find the value.
Stop searching the web for date formats, query the database
Michael M.
Simple query to show you all the date time formats in the database.
Show the DDL Code for a View
Show the user’s login security
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
SELECT sys.dm_exec_connections.session_id AS SPID , sys.dm_exec_connections.connect_time AS Connect_Time , DB_NAME(dbid) AS DatabaseName , loginame AS LoginName , sys.dm_exec_connections.auth_scheme as Auth_Scheme , sys.dm_exec_connections.net_transport AS Net_Transport , sys.dm_exec_connections.protocol_type as Protocol_Type , sys.dm_exec_connections.client_net_address as Client_Net_Address , sys.dm_exec_connections.local_net_address as Local_Net_Address , sys.dm_exec_connections.local_tcp_port as Local_TCP_Port FROM sys.sysprocesses Right Outer JOIN sys.dm_exec_connections ON sys.sysprocesses.spid=sys.dm_exec_connections.session_id Order By Auth_Scheme, Net_Transport ; |
How big is it? Big? Really Big? Ginormous???
Yesterday, I posted a quick query Column Names by Table on how to search for a column in any table in the database. Today’s query will extend that functionality to let you know how many rows are in the table while avoiding the dreaded
SELECT COUNT(*) FROM dbo.SuperHugeTable;
Where is it? Seriously, where is it?
We’ve all had the experience of trying to locate a specific column name or wanting to see the meta-data for columns in a specific or multiple tables. By reading the information schema tables we can see the meta-data and find all occurences of the column in the database. This information can be quite useful when needing to join columns and finding some hidden relationships.
“Why doesn’t this function exist?”
We have all had the situation where there is a need for a little custom function to modify strings or do simple math on a column. Today I am going to show how to create a User Defined Function (UDF) in Microsoft SQL.
Oracle PL/SQL Aggregation – Rank
One of the more interesting aggregation functions is RANK. After doing a standard SELECT and GROUP BY; you can then have SQL rank the results using an aggregated value from another column.
Let’s dive in and look at how RANK works and what can it do for us.
Limit Rows Returned
Previous to Oracle 12c limit the number of rows returned usually meant encapsulating the query as a subquery. It wasn’t particularly nice looking and was out of alignment with other relational database query languages.
MySQL uses the LIMIT operator and Microsoft T-SQL uses the TOP operator. In Oracle 12c, Oracle introduced the FETCH FIRST operator. Let’s see how it works.