Sqlsever implements field name change

Source: Internet
Author: User

Create a table:
Create table [table name]
(
[Automatic number field] int IDENTITY (1, 1) primary key,
[Field 1] nVarChar (50) default 'default value 'null,
[Field 2] ntext null,
[Field 3] datetime,
[Field 4] money null,
[Field 5] int default 0,
[Field 6] Decimal (12, 4) default 0,
[Field 7] image null,
)

Delete table:
Drop table [table name]

Insert data:
Insert into [Table name] (Field 1, Field 2) VALUES (100, '51windows. net ')

Delete data:
Delete from [Table name] WHERE [field name]> 100

Update Data:
UPDATE [Table name] SET [Field 1] = 200, [Field 2] = '51windows. net' WHERE [Field 3] = 'haiwa'

New field:
Alter table [TABLE name] ADD [field name] NVARCHAR (50) NULL

Delete field:
Alter table [TABLE name] drop column [field name]

Modify Field:
Alter table [TABLE name] alter column [field name] NVARCHAR (50) NULL

Rename a table:(For details about how to rename an Access Table, refer to: Renaming a table in an Access database)
Sp_rename 'table name', 'new table name', 'object'

New constraint:
Alter table [TABLE name] add constraint name CHECK ([CONSTRAINT field] <= '2017-1-1 ')

Delete constraints:
Alter table [TABLE name] drop constraint name

Create Default Value
Alter table [TABLE name] add constraint default name: '51windows. net' FOR [field name]

Delete default value
Alter table [TABLE name] drop constraint default name

In addition, most of the preceding SQL syntaxes are the same under ACCESS.

Check the item and verify it by yourself. Make sure that the following method is suitable for adding an automatic number field to the access Database: create table data table name (id counter constraint primarykey primary key) note that the second primary contains spaces. In addition, the keywords are case insensitive. another method I recently discovered is: SQL = "create table mytb (id autoincrement () primary key, age int)" sql2 = "create table testtb (id autoincrement, age int, email char, primary key (id) "in access, autoincrement is an automatically numbered field, and () is the initial value and step value. If no value is specified, the default value is. The primary key specifies the primary key. In the preceding example, either of the two methods can be used.

2. Change the field name (column name)

Sp_rename 'table name. Original column name', 'Modified column name', 'column'

For example, change the doc_id column name in the tb_wf_approveinfo table to bind_id:

Sp_rename 'tb_wf_approveinfo.doc _ id', 'Bind _ id', 'column'

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.