Create and modify a table

Source: Internet
Author: User
Create a table

Create Table Name

(

The column name, type name, and constraint are generally used in the table (can be added or not added)

If the name of the column is the same as that of the system keyword, the color of the column name does not change, but it can be distinguished by adding,

)

A table has at least one column and a maximum of 1024 columns. up to 2 million tables can be created in each database.

Special terms in the table:

Relational: tables in the database

Attribute field: column in the table

Tuples: rows in the table

Field: column value range

Component: column value of a column in a row

Link mode: Description of the table (table name (column name 1, column name 2 ......))

 

Execution of the selected statement points shows the result.

 

Modify Table

If the table structure cannot be modified in SQL Server 2008, the following error occurs: Save and modify is not allowed ,......

Solution: designer table designer and DB designer on the left of tool options

Remove the hook above "change to prevent table creation required for saving" and restart the system.

Add column: alter table table name Add column name column type

 

Delete column: alter table Table Name drop column name

 

Alter column type: alter table name alter column name New Type

 

-- Insert add)

Application: The table structure remains unchanged. Only one row or a value can be added.

-- Xuliehao can be assigned only when it is not self-increasing. column names are separated by commas (,) without quotation marks.

-- The order of values is the order of the table by default. If the input values are incomplete, you can add the names of the columns to be input. The order is one to one.

-- Values Value

Insert into fruit values ('1', 'hongfu', '5', 'apple ')

Insert into fruit (xuliehao, name, jiage) values ('2', 'green watermelon ', '1 ')

Insert into fruit (xuliehao, name, [type]) values ('3', 'jufeng', '6 ')

 

 

* ** Columns set to auto-increment cannot be assigned a value (the auto-increment value must be an integer type)

Delete

Delete from table name Delete table content (the table structure is still in) This deletion method will write logs, so the self-increasing serial number will continue, increasing will not start from scratch

Truncate table name this delete operation clears the table, which is fast and does not write logs.

Delete from table name where column name relational expression value

You can add and or to multiple conditions.

Column name between value 1 and value 2 is equivalent to column name <= value 2 and column Name> = value 1

Column name in (value 1, value 2, value 3 ,...) The filtered value is one, two, or three... Options

Press Ctrl + 0 to select a data value in the table. The value becomes null.

Update (update)

Update table name set column name = value, column name = value ...... Where column name relational expression value

 

Create and modify a table

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.