information-schema

Search a column name across all databases

牧云@^-^@ 提交于 2019-12-01 04:44:37
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. This script will search your column in all tables across all databases. Create table #yourcolumndetails(DBaseName varchar(100), TableSchema varchar(50), TableName varchar(100),ColumnName varchar(100), DataType varchar(100), CharMaxLength

Query the schema details of a table in PostgreSQL?

大兔子大兔子 提交于 2019-11-30 09:36:51
I need to know the column type in PostgreSQL (i.e. varchar(20) ). I know that I could probably find this using \d something in psql, but I need it to be done with a select query. Is this possible in PostgreSQL? Alexandre GUIDET You can fully describe a table using postgres with the following query: SELECT a.attname as Column, pg_catalog.format_type(a.atttypid, a.atttypmod) as Datatype FROM pg_catalog.pg_attribute a WHERE a.attnum > 0 AND NOT a.attisdropped AND a.attrelid = ( SELECT c.oid FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relname ~

What is the most portable way to check whether a trigger exists in SQL Server?

。_饼干妹妹 提交于 2019-11-30 06:34:08
问题 I'm looking for the most portable method to check for existence of a trigger in MS SQL Server. It needs to work on at least SQL Server 2000, 2005 and preferably 2008. The information does not appear to be in INFORMATION_SCHEMA, but if it is in there somewhere, I would prefer to use it from there. I do know of this method: if exists ( select * from dbo.sysobjects where name = 'MyTrigger' and OBJECTPROPERTY(id, 'IsTrigger') = 1 ) begin end But I'm not sure whether it works on all SQL Server

List all tables in postgresql information_schema

限于喜欢 提交于 2019-11-30 06:09:32
问题 What is the best way to list all of the tables within PostgreSQL's information_schema? To clarify: I am working with an empty DB (I have not added any of my own tables), but I want to see every table in the information_schema structure. 回答1: You should be able to just run select * from information_schema.tables to get a listing of every table being managed by Postgres for a particular database. You can also add a where table_schema = 'information_schema' to see just the tables in the

Query the schema details of a table in PostgreSQL?

若如初见. 提交于 2019-11-29 14:20:59
问题 I need to know the column type in PostgreSQL (i.e. varchar(20) ). I know that I could probably find this using \d something in psql, but I need it to be done with a select query. Is this possible in PostgreSQL? 回答1: You can fully describe a table using postgres with the following query: SELECT a.attname as Column, pg_catalog.format_type(a.atttypid, a.atttypmod) as Datatype FROM pg_catalog.pg_attribute a WHERE a.attnum > 0 AND NOT a.attisdropped AND a.attrelid = ( SELECT c.oid FROM pg_catalog

How to limit SHOW TABLES query

元气小坏坏 提交于 2019-11-29 12:38:34
问题 I have the following query: SHOW TABLES LIKE '$prefix%' It works exactly how I want it to, though I need pagination of the results. I tried: SHOW TABLES LIKE '$prefix%' ORDER BY Comment ASC LIMIT 0, 6 I need it to return all the tables with a certain prefix and order them by their comment. I want to have pagination via the LIMIT with 6 results per page. I'm clearly doing something very wrong. How can this be accomplished? EDIT: I did look at this. It didn't work for me. 回答1: The above cannot

Set empty strings ('') to NULL in the whole database

北城以北 提交于 2019-11-29 08:49:22
In my database are many text columns where values are empty strings ( '' ). The empty strings need to be set to NULL . I do not know the exact schemas, tables and columns in this database or rather I want to write a general solution which can be reused. How would I write a query / function to find all text columns in all tables in all schemas and update all columns with empty strings ( '' ) to NULL ? Erwin Brandstetter The most efficient way to achieve this: Run a single UPDATE per table. Only update nullable columns (not defined NOT NULL ) with any actual empty string. Only update rows with

What is the most portable way to check whether a trigger exists in SQL Server?

Deadly 提交于 2019-11-28 20:03:29
I'm looking for the most portable method to check for existence of a trigger in MS SQL Server. It needs to work on at least SQL Server 2000, 2005 and preferably 2008. The information does not appear to be in INFORMATION_SCHEMA, but if it is in there somewhere, I would prefer to use it from there. I do know of this method: if exists ( select * from dbo.sysobjects where name = 'MyTrigger' and OBJECTPROPERTY(id, 'IsTrigger') = 1 ) begin end But I'm not sure whether it works on all SQL Server versions. wqw This works on SQL Server 2000 and above IF OBJECTPROPERTY(OBJECT_ID('{your_trigger}'),

List all tables in postgresql information_schema

☆樱花仙子☆ 提交于 2019-11-28 15:08:34
What is the best way to list all of the tables within PostgreSQL's information_schema? To clarify: I am working with an empty DB (I have not added any of my own tables), but I want to see every table in the information_schema structure. You should be able to just run select * from information_schema.tables to get a listing of every table being managed by Postgres for a particular database. You can also add a where table_schema = 'information_schema' to see just the tables in the information schema. phsaires For listing your tables use: SELECT table_name FROM information_schema.tables WHERE

Information schema and Primary Keys

一世执手 提交于 2019-11-28 13:35:26
How do I just print out a 'primary key' for the column with the primary key? I get 'primary key' for all the columns if the table has a primary key, instead of the one column with the primary key and the other columns as blank in keyType. SELECT c.TABLE_NAME, c.COLUMN_NAME, c.DATA_TYPE, c.Column_default, c.character_maximum_length, c.numeric_precision, c.is_nullable, CASE WHEN u.CONSTRAINT_TYPE = 'PRIMARY KEY' THEN 'primary key' ELSE '' END AS KeyType FROM INFORMATION_SCHEMA.COLUMNS as c LEFT JOIN information_schema.table_constraints as u ON c.table_name = u.table_name ORDER BY table_name