Common commands used by SQL Server

Source: Internet
Author: User


Create a database

CREATE DATABASE database_name

Example: CREATE DATABASE Test

Execute commands first when creating a table

Use test

Create a table

CREATE TABLE table name (column name 1 data type, column name 2 data type, ... )

Example: Create table book (name char), writer varchar (20))

You can set some fields to be self-increment when you create a table, but the field property must be of type int

The CREATE TABLE table name (column name int identity (A, b)) A represents the increment starting from a,

Increase the B value each time (note that both A and B must be int and cannot set the word length)

Example: Create TABLE book (book_id int identity)

Inserting data into the table

Insert into Table name values (field value, field two value, ...)

Example: INSERT into book values (' Wolf totem ', ' Jiangrong ')

Note the field values of the varchar and char types are inserted in single quotation marks

To modify the data type of a column in a table

ALTER TABLE name ALTER COLUMN name new data type

Example: ALTER TABLE book ALTER COLUMN varchar (20)

Delete all field values in a table

Delete Table name

Example: Delete book

Delete a table

DROP table Name

Example: Drop book

View the details of a table

sp_help table Name

Example: Sp_help book

Copy all of the data from table 1 to table 2:

INSERT INTO table1 select * from table2

Common commands used by SQL Server

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.