SQL queries whether a table exists and returns the ID of the new data

Source: Internet
Author: User

The following is a brief description of the SQL query for the existence of a table and returns the ID value of the new data.

1. Whether the query table exists:

table name: "T_demo", type = ' u ' See if it is a user table

SELECT * from sysobjects where id = object_id (' T_demo ') and type = ' u ' select * from sys.tables where name= ' T_demo ' and Typ e = ' u '

2. Whether the query field exists:

Table name: "t_demo", Field name "Demoid"

SELECT * from syscolumns where name= ' demoid ' and objectproperty (ID, ' isusertable ') =1 andobject_name (id) = ' t_demo '

3. Returns the maximum value of a self-increment field that can be used to return the ID value of the data just added.

Field name: Ndsid table name: tb_nds

Select Max (NDSID) from Tb_nds


This article is from the "World is the same" blog, please be sure to keep this source http://970076933.blog.51cto.com/9767314/1886538

SQL queries whether a table exists and returns the ID of the new data

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.