How to Create a table on SQL Server

Source: Internet
Author: User

Use SQL Server to create a simple table

Because two identical tables are not allowed in the same database, you should determine whether the table exists before creating a new table. Therefore, two functions are used.

 

I,

Object_id:
Returns the ID of the database object.

Syntax
Object_id ('object ')

Parameters
'Object'

The object to use. The object data type is Char or nchar. If the object data type is Char, It is implicitly converted to nchar.

Return type
Int

Example
The following example shows the ID of the object returned from the authors table in the pubs database.

Use master
Select object_id ('pubs .. Authors ')

The following is the result set:

-----------
1977058079

(1 row (s) affected)

(2)

Objectproperty

Returns information about objects in the current database.

 

Syntax

Objectproperty (ID, property)

ID
 
Is the expression that represents the Object ID in the current database. IDThe data type of is IntAnd it is assumed that it is an object within the framework range of the current database context.
Property
 
An expression that provides IDReturned information of the specified object

There are many property options, so we will not list them here. The name of the istable attribute is a table, and the return value 1 is true, and the value 0 is false.

 

Example

 

Test whether authors is a table.

 

If objectproperty (object_id ('authors '), 'istable') = 1

Print 'authors is a table'

 

Else if objectproperty (object_id ('authors '), 'istable') = 0

Print 'authors is not a table'

 

Else if objectproperty (object_id ('authors '), 'istable') is null

Print 'error: authors is not an Object'

 

 

 

 

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.