information-schema

MSSQL: How do you script Stored Procedure creation with code?

白昼怎懂夜的黑 提交于 2020-01-01 14:48:52
问题 I am trying to query for a list of stored procedure definitions using information_schema.routines that exist in one database but not in another. SELECT t1.Routine_Definition FROM [server1].MyDatabase.INFORMATION_SCHEMA.Routines t1 LEFT JOIN [server2].MyDatabase.INFORMATION_SCHEMA.Routines t2 ON t1.Routine_Name = t2.Routine_Name WHERE t2.Routine_Name is null This gives me the query definitions in a single line so when I have a comment like this --Some comment SELECT Column FROM Somewhere The

MySQL: How can I get the timestamp of the last insertion to the database

怎甘沉沦 提交于 2019-12-31 01:50:29
问题 How can I check when was the last time (timestamp) that I wrote in the database, irrespectively of the database table that I inserted into? 回答1: Turned out to not be the answer (can't delete as accepted). See comments below this answer. I wasn't able to use information_schema.tables update_time as the column wasn't being updated but for create_time this worked. It would work for update_time (if changed) if update_time gets updated which might be true in your setup. select table_schema,table

Search a column name across all databases

无人久伴 提交于 2019-12-30 08:58:09
问题 I have this query that finds all tables and views that matches my column name of a certain database. I am using SQL SERVER 2008 SELECT table_name FROM information_schema.columns WHERE column_name = 'product_name' I want to extend the capability of my query to search across all databases and even look for Stored procedures whose having my searched column name. 回答1: This script will search your column in all tables across all databases. Create table #yourcolumndetails(DBaseName varchar(100),

How do I find a default constraint using INFORMATION_SCHEMA?

跟風遠走 提交于 2019-12-28 08:04:47
问题 I'm trying to test if a given default constraint exists. I don't want to use the sysobjects table, but the more standard INFORMATION_SCHEMA. I've used this to check for tables and primary key constraints before, but I don't see default constraints anywhere. Are they not there? (I'm using MS SQL Server 2000). EDIT: I'm looking to get by the name of the constraint. 回答1: As I understand it, default value constraints aren't part of the ISO standard, so they don't appear in INFORMATION_SCHEMA.

Finding MIN and MAX Values for All Table Columns

流过昼夜 提交于 2019-12-24 14:38:59
问题 This query works as intended, but it's just really slow. Does anyone here have recommendations to improve performance? I essentially just creating a temp table to store all the table and column names, and cycling through them via a WHILE statement, to create dynamic inserts into another table with the details I want. My latest run took about 21 minutes, which isn't entirely terrible (considering the task), but I'd love to get some input on how/where it can be fine tuned. USE <DATABASE>; IF

Querying the appropriate database schema

♀尐吖头ヾ 提交于 2019-12-24 10:18:16
问题 This is a follow-on question to my earlier question about specifying multiple schemata in java using jooq to interact with H2. My test H2 DB currently has 2 schemata, PUBLIC and INFORMATION_SCHEMA. PUBLIC is specified as the default schema by H2. When running a query that should extract information from eg INFORMATION_SCHEMA.TABLES the query fails with a "table unknown" SQL error. I am only able to execute such queries by executing a factory.use(INFORMATION_SCHEMA) . There are no build errors

Generate INFORMATION_SCHEMA table for MySQL database

柔情痞子 提交于 2019-12-24 04:23:18
问题 I'm using an old version of MySQL (4.0) on an old server and for some reason it has no INFORMATION_SCHEMA database, I don't know if this version of MySQL did not include INFORMATION_SCHEMA or if someone deleted it. Is there some way to (re)Generate this database? thanks # mysql --version mysql Ver 12.22 Distrib 4.0.18, for suse-linux (x86_64) 回答1: The INFORMATION_SCHEMA database was added in MySQL 5.02. It's not possible to create or delete it. It's managed by the server directly. Instead of

How to check which function uses a type?

久未见 提交于 2019-12-24 01:05:28
问题 I have a type which I'd like to change but I don't know who else is using it. How can I check for all functions that return this type? 回答1: You can find all dependencies in the system catalog pg_depend. This returns all functions depending on the type . I.e. not only those with the type in the RETURNS clause, but also those with the type as function parameter: SELECT objid::regproc AS function_name , pg_get_functiondef(objid) AS function_definition , pg_get_function_identity_arguments(objid)

Updating empty string to NULL for entire database

爱⌒轻易说出口 提交于 2019-12-22 14:54:43
问题 I'm performing some database clean up and have noticed that there are a lot of columns that have both empty strings and NULL values in various columns. Is it possible to write an SQL statement to update the empty strings to NULL for each column of each table in my database, except for the ones that do not allow NULL's? I've looked at the information_schema.COLUMNS table and think that this might be the place to start. 回答1: It's not possible to do this with one simple SQL statement. But you

SQL Server 2008 grant permission to information_schema.columns

风格不统一 提交于 2019-12-22 04:20:33
问题 I have a series of stored procedures that select data from a db. I have a role (cctc_reader) that has execute permissions granted on the procedures. One of the procedure calls another stored procedure called recControl_system_option which in turn queries Information_schema.columns . The problem is that in this proc the query select column_name from information_schema.columns where table_name = 'recControl_manager' does not return any records. cctc_reader has grant permissions on: each select