information-schema

How to select Unknown Number of Columns in mysql?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 11:48:48
问题 Given the table and names of some columns, I have the following Information schema select query. SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA` = 'm_college' AND `TABLE_NAME` = 'm_fee' AND COLUMN_NAME NOT IN ('id', 'classid', 'semid') But this select does not give me the rows value for each unknown column I select. All I got is names of the unknown columns. Is it possible to select the values of the rows so that I can have column as key and rows as value pair in

MySQL - querying average row length

你。 提交于 2019-12-07 10:33:05
问题 I have a table named rabbits. I am trying to find the average row length in my table. I tried this query: SELECT AVG_ROW_LENGTH(rabbits) but it doesn't work. 回答1: My Googling has indicated that AVG_ROW_LENGTH is actually a column in information_schema.tables. You'll want to try something like this, I think: SELECT AVG_ROW_LENGTH FROM information_schema.tables WHERE TABLE_NAME = 'rabbits'; You may also need to specify the database name by adding "AND TABLE_SCHEMA = 'databasename';" if you have

Updating empty string to NULL for entire database

烈酒焚心 提交于 2019-12-06 06:49:16
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. It's not possible to do this with one simple SQL statement. But you can do it using one statement for each column. UPDATE TABLE SET COLUMN = NULL WHERE LENGTH(COLUMN) = 0 or, if

MySQL - querying average row length

。_饼干妹妹 提交于 2019-12-05 18:12:25
I have a table named rabbits. I am trying to find the average row length in my table. I tried this query: SELECT AVG_ROW_LENGTH(rabbits) but it doesn't work. Redbeard011010 My Googling has indicated that AVG_ROW_LENGTH is actually a column in information_schema.tables. You'll want to try something like this, I think: SELECT AVG_ROW_LENGTH FROM information_schema.tables WHERE TABLE_NAME = 'rabbits'; You may also need to specify the database name by adding "AND TABLE_SCHEMA = 'databasename';" if you have more than one database with a rabbits table. Hope this helps! You can't SELECT that, try

List grants and privileges for a materialized view in PostgreSQL

空扰寡人 提交于 2019-12-05 14:29:00
问题 I need to determine what privileges are currently granted for some materialized views in my database. The query to do this for a table or standard view is pretty straight forward: SELECT grantee, string_agg(privilege_type, ', ') AS privileges FROM information_schema.table_privileges WHERE table_schema = 'some_schema' AND table_name = 'some_table' GROUP by grantee; That said, there doesn't seem to be an analogous table for materialized views. Where does PostgreSQL store this information? 回答1:

SQL Server 2008 grant permission to information_schema.columns

时光毁灭记忆、已成空白 提交于 2019-12-05 03:23:49
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 proc recControl_system_option so in theory this should work. I have no problems when run under dbo. If

How can I get SQL Server column definition with parentheses and everything?

旧时模样 提交于 2019-12-05 01:03:08
问题 I need a smart way to get the data types out of INFORMATION_SCHEMA.COLUMNS in a way that could be used in a CREATE TABLE statement. The problem is the 'extra' fields that need to be understood, such as NUMERIC _ PRECISION and NUMERIC _ SCALE. Obviously, I can ignore the columns for INTEGER (precision of 10 and scale of 0), but there are other types I would be interested in, such as NUMERIC. So without writing lots of code to parse the table, any ideas on how to get a sort of field shorthand

Creating a site to query a database of tables

心已入冬 提交于 2019-12-04 03:20:33
问题 I have a small problem. I am working with some manual testers who are untrained in programming/database design. Our current process means that these manual testers need to insert data into our database at certain times whilst we build a GUI to facilitate this in the future. In the interim, I would like to create a simple site. What I would like to do with the site is, simply, connect to our database, allow the manual tester to enter some keywords, and return any columns within tables that are

List grants and privileges for a materialized view in PostgreSQL

拟墨画扇 提交于 2019-12-04 01:02:57
I need to determine what privileges are currently granted for some materialized views in my database. The query to do this for a table or standard view is pretty straight forward: SELECT grantee, string_agg(privilege_type, ', ') AS privileges FROM information_schema.table_privileges WHERE table_schema = 'some_schema' AND table_name = 'some_table' GROUP by grantee; That said, there doesn't seem to be an analogous table for materialized views. Where does PostgreSQL store this information? In Postgres system catalogs are the basic set of complete information about the installation and databases.

Finding columns that are NOT NULL in PostgreSQL

拟墨画扇 提交于 2019-12-03 23:27:37
I had an assignment for each table to count nullable columns. Easy: SELECT table_name, count(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE is_nullable='NO' GROUP BY table_name; Now I have to modify this to count "columns that have property "NOT NULL"". Will the following code do this or will it just check weather column name is not null? CREATE TEMP TABLE A AS SELECT DISTINCT column_name, table_name AS name FROM INFORMATION_SCHEMA.COLUMNS WHERE column_name IS NOT NULL GROUP BY table_name, column_name; SELECT name, count(*) FROM A GROUP BY name; If no... Any advices? No. This query SELECT DISTINCT