information-schema

How can I test if a column exists in a table using an SQL statement

感情迁移 提交于 2019-11-27 04:26:49
问题 Is there a simple alternative in PostgreSQL to this statement produced in Oracle? select table_name from user_tab_columns where table_name = myTable and column_name = myColumn; I am then testing whether the query returns anything so as to prove the column exists. I am aware that using psql I can find these out individually but this is required to produce a result in a program I am writing to validate that a requested attribute field exists in my database table. 回答1: Try this : SELECT column

SQL Server: How to tell if a database is a system database?

强颜欢笑 提交于 2019-11-26 17:13:57
问题 I know that so far (until MSSQL 2005 at least), system databases are master, model, msdb and tempdb. Thing is, as far as I can tell, this is not guaranteed to be preserved in the future. And neither the sys.databases view nor the sys.sysdatabases view tell me if a database is considered as a system database. Is there someplace where this information (whether a database is considered a system database or not) can be obtained? 回答1: Just dived into Microsoft.SqlServer.Management.Smo.Database

MySQL disable all triggers

旧城冷巷雨未停 提交于 2019-11-26 16:53:05
问题 For test correctness of query I need disable all triggers in db. I see that in information_schema exists table TRIGGERS. Is possible temporarily disable all triggers using this table? E.g. like: update TRIGGERS set TRIGGERS_SCHEMA='myschema_new' where TRIGGERS_SCHEMA='myschema' and after finish all test return all triggers like: update TRIGGERS set TRIGGERS_SCHEMA='myschema' where TRIGGERS_SCHEMA='myschema_new' May be this can corrupt db or after triggers will not works? I didn't found about

SQL Server: Howto get foreign key reference from information_schema?

拥有回忆 提交于 2019-11-26 16:11:05
In SQL Server, how can I get the referenced table + column name from a foreign key? Note: Not the table/column where the key is in, but the key it refers to. Example: When the key [FA_MDT_ID] in table [T_ALV_Ref_FilterDisplay] . refers to [T_AP_Ref_Customer].[MDT_ID] such as when creating a constraint like this: ALTER TABLE [dbo].[T_ALV_Ref_FilterDisplay] WITH CHECK ADD CONSTRAINT [FK_T_ALV_Ref_FilterDisplay_T_AP_Ref_Customer] FOREIGN KEY([FA_MDT_ID]) REFERENCES [dbo].[T_AP_Ref_Customer] ([MDT_ID]) GO I need to get [T_AP_Ref_Customer].[MDT_ID] when given [T_ALV_Ref_FilterAnzeige].[FA_MDT_ID]

How to check if a Constraint exists in Sql server?

 ̄綄美尐妖づ 提交于 2019-11-26 12:49:25
问题 I have this sql: ALTER TABLE dbo.ChannelPlayerSkins DROP CONSTRAINT FK_ChannelPlayerSkins_Channels but apparently, on some other databases we use, the constraint has a different name. How do I check if there\'s a constraint with the name FK_ChannelPlayerSkins_Channels . 回答1: try this: SELECT * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS WHERE CONSTRAINT_NAME ='FK_ChannelPlayerSkins_Channels' -- EDIT -- When I originally answered this question, I was thinking "Foreign Key" because the

SQL Server: Howto get foreign key reference from information_schema?

依然范特西╮ 提交于 2019-11-26 04:45:57
问题 In SQL Server, how can I get the referenced table + column name from a foreign key? Note: Not the table/column where the key is in, but the key it refers to. Example: When the key [FA_MDT_ID] in table [T_ALV_Ref_FilterDisplay] . refers to [T_AP_Ref_Customer].[MDT_ID] such as when creating a constraint like this: ALTER TABLE [dbo].[T_ALV_Ref_FilterDisplay] WITH CHECK ADD CONSTRAINT [FK_T_ALV_Ref_FilterDisplay_T_AP_Ref_Customer] FOREIGN KEY([FA_MDT_ID]) REFERENCES [dbo].[T_AP_Ref_Customer] (

How to find all the tables in MySQL with specific column names in them?

爷,独闯天下 提交于 2019-11-25 23:24:28
问题 I have 2-3 different column names that I want to look up in the entire DB and list out all tables which have those columns. Any easy script? 回答1: To get all tables with columns columnA or ColumnB in the database YourDatabase : SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME IN ('columnA','ColumnB') AND TABLE_SCHEMA='YourDatabase'; 回答2: SELECT TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME LIKE '%wild%'; 回答3: More simply done in one line

How to check if a table exists in a given schema

你离开我真会死。 提交于 2019-11-25 22:31:20
问题 Postgres 8.4 and greater databases contain common tables in public schema and company specific tables in company schema. company schema names always start with \'company\' and end with the company number. So there may be schemas like: public company1 company2 company3 ... companynn An application always works with a single company. The search_path is specified accordingly in odbc or npgsql connection string, like: search_path=\'company3,public\' How would you check if a given table exists in