Home > Database > Mysql Tutorial > body text

SQL for commonly used database queries to determine whether tables and fields exist

大家讲道理
Release: 2016-11-12 09:34:16
Original
3656 people have browsed it

SQL for commonly used database queries to determine whether tables and fields exist (if the result is 1, it means it exists, and 0 means it does not exist)

1. MSSQL Server
Table:

SELECT COUNT(*) FROM dbo.sysobjects 
WHERE name= 'table_name';
Copy after login

Field:

SELECT COUNT(*) FROM syscolumns 
WHERE id=object_id(‘table_name’) AND name= 'column_name';
Copy after login


2. My SQL
Table:

SELECT COUNT(*) FROM information_schema.tables 
WHERE table_name ='table_name';
Copy after login

Field:

SELECT COUNT(*) FROM information_schema.columns 
WHERE table_name ='table_name' AND column_name ='column_name';
Copy after login


3. Oracle
Table:

SELECT count(*) FROM USER_OBJECTS 
WHERE OBJECT_NAME = 'table_name';
Copy after login

Field:

SELECT COUNT(*) FROM USER_TAB_COLUMNS 
WHERE TABLE_NAME ='table_name' AND column_name ='column_name';
Copy after login


4. PostgreSql
Table:

SELECT count(*) FROM information_schema.tables 
WHERE table_schema='table_schema' AND table_name ='table_name';
Copy after login

Field:

SELECT count(*) FROM information_schema.columns 
WHERE table_schema='table_schema' AND table_name ='table_name' AND column_name='column_name';
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template