SQL Server Database Tutorial Two, creating a database table

Source: Internet
Author: User

1. Create a table

Grammar:

CREATE Table Table Name

(

Column Name 1 data type 1,

Column Name 2 data type 2,

Column Name 3 data type 3,

)

For example:

CREATE TABLE Teachers (    varchar,    bit  ,     integer  )

2. Create a table in the specified database

Using the USE statement to reference the specified database, you can create a table in the database

Grammar:

Use database name

CREATE Table Table Name

(

Column Name 1 data type 1,

Column Name 2 data type 2,

Column Name 3 data type 3,

)

For example:

 Use Customers CREATE TABLE Teachers (    varchar,    bit  ,    integer) 

Some of the data types commonly used in SQL are summarized in the following table:

Data type Describe

Integer (size)

int (size)

smallint (size)

tinyint (size)

Holds integers only. Specify the maximum number of digits within the parentheses.

Decimal (SIZE,D)

Numeric (SIZE,D)

Accommodates numbers with decimals.

"Size" Specifies the maximum number of digits. "D" Specifies the maximum number of digits to the right of the decimal point.

char (size)

Holds a fixed-length string (which can hold letters, numbers, and special characters).

Specifies the length of the string in parentheses.

varchar (size)

Accommodates variable-length strings that can hold letters, numbers, and special characters.

Specifies the maximum length of the string in parentheses.

Date (YYYYMMDD) accommodate the date.

SQL Server Database Tutorial Two, creating a database table

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.