SQL database SQL statements

Source: Internet
Author: User

Not written for a long timeArticleNow,

Today, I practiced some SQL statements to operate table indexes and columns to make a record.

The format for creating an index is different from that for creating a constraint. Do not confuse it.

 

Create a table

Create Table plane
(
Id int identity (1, 1) not null,
Planeid int not null,
Persion nvarchar (50) not null,
Addtime datetime default getdate () not null
Constraint pk_plane primary key clustered (id asc) -- ID is the primary key and is used to write clustered index SQL. Other databases have not tried
)

Create a non-clustered index nonclustered clustered index clustered

Create nonclustered index idx_plane on plane (planeid)

 

Delete Index

Drop index idx_plane on Plane

 

Add Column

Alter table plane add num int not null default 0

 

Modify the column type. If the column has constraints or indexes, delete the index or constraints first.

Alter table plane alter column num varchar (100)

 

Add default Constraints

Alter table plane add constraint df_planename default ('fd ') for planename

 

Delete Constraints

Alter table plane drop df_planename

 

When I get off work, I copy others' records to make a record.

-- Add description information for the table
Execute sp_addextendedproperty n 'Ms _ description', 'personnel info table ', N 'user', N 'dbo', N 'table', N 'table', null, null

-- Add description information for field A1
Execute sp_addextendedproperty n 'Ms _ description', 'name', N 'user', N 'dbo', N 'table', N 'table', N 'column ', n'field'

-- Add description information for field A2
Execute sp_addextendedproperty n 'Ms _ description', 'gender', N 'user', N 'dbo', N 'table', N 'table', N 'column ', n'field'

-- Update the description attribute of column A1 in the table:
Exec sp_updateextendedproperty 'Ms _ description', 'field 1', 'user', DBO, 'table', 'table', 'column', 'field'

-- Delete the description attribute of column A1 in the table:
Exec sp_dropextendedproperty 'Ms _ description', 'user', DBO, 'table', 'table', 'column ', 'field'

 

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.