Common Database queries (determining whether tables and fields exist)

Source: Internet
Author: User
Table_name and column_name are both uppercase: 1. MSSQLServer table: selectcount (*) fromdbo. sysobjectswherenametable_name; field: selectcount (*) fromsyscolumnswherecolumn_name; 2. MySQL table: sel

The table_name and column_name parameters are both uppercase: 1. MSSQL Server table: select count (*) from dbo. sysobjects where name = 'table _ name'; field: select count (*) from syscolumns where id = object_id ('table _ name') and name = 'column _ name '; 2. My SQL table: sel

The values of table_name and column_name are uppercase:

1. MSSQL Server

Table: select count (*) from dbo. sysobjects where name = 'table _ name ';
Field: select count (*) from syscolumns where id = object_id ('table _ name') and name = 'column _ name ';


2. My SQL

Table: select count (*) from information_schema.tables where table_name = 'table _ name ';
Field: select count (*) from information_schema.columns where table_name = 'table _ name' and column_name = 'column _ name ';


3. Oracle

Table: select count (*) from user_objects where object_name = 'table _ name ';
Field: select count (*) from user_tab_columns where table_name = 'table _ name' and column_name = 'column _ name ';


4. PostgreSql

Table: select count (*) from information_schema.tables where table_schema = 'table _ scheme' and table_name = 'table _ name ';
Field: select count (*) from information_schema.columns where table_schema = 'table _ scheme' and table_name = 'table _ name' and column_name = 'column _ name ';

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.