SQL Server and Oracle determine if tables and columns exist

Source: Internet
Author: User

Sql server

1. Determine whether the table users existif object_id(N'Users'N'U') is  not NULL    Print 'exist'Else     Print 'does not exist'    2. Determine if the Name column exists in the table usersif exists(Select *  fromsyscolumnswhereId=object_id('Users') andName='Name'collate Chinese_prc_ci_ai_ws)Print 'exist'Else    Print 'does not exist'Note: Collate chinese_prc_ci_ai_ws represents case-insensitive

Oracle

1. Judging whether the table is a villageDeclare   --here is the local variableIinteger;begin  --here is the test statement  Select Count(1) intoI fromAll_tableswheretable_name='Site_info'  andOwner='WIFI'; if(I>0)   ThenDbms_output.put_line ('exist'); ElseDbms_output.put_line ('does not exist'); End if;End;2. Determine if a column existsDeclare   --here is the local variableIinteger;begin  --here is the test statement  Select Count(1) intoI fromAll_tab_columnswhereOwner='WIFI'  andtable_name='Site_info'  andcolumn_name='site_id'; if(I>0)   ThenDbms_output.put_line ('exist'); ElseDbms_output.put_line ('does not exist'); End if;End;

Description: PL/SQL needs to create a new test window to run the above statement

SQL Server and Oracle determine if tables and columns exist

Related Article

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.