Sqlsever implementation change field name _mssql

Source: Internet
Author: User
Tags access database

New table:
CREATE table [table name]
(
AutoNumber field int IDENTITY (1,1) PRIMARY KEY,
[Field 1] nVarChar default ' defaults ' 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,
)

To delete a table:
Drop table [table name]

Insert data:
INSERT into [table name] (field 1, Field 2) VALUES (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 three] = ' Haiwa '

New fields:
ALTER table [table name] ADD [field name] NVARCHAR (m) NULL

To delete a field:
ALTER table [table name] DROP COLUMN [field name]

To modify a field:
ALTER TABLE [table name] ALTER COLUMN [field name] NVARCHAR (m) NULL

To rename a table: (Access renames a table, refer to the article: rename a table in an Access database)
sp_rename ' table name ', ' New table name ', ' OBJECT '

New constraint:
ALTER table [table name] ADD CONSTRAINT constraint name CHECK ([constraint field] <= ' 2000-1-1 ')

Delete constraint:
ALTER table [table name] DROP CONSTRAINT constraint name

Create a new default value
ALTER table [table name] ADD CONSTRAINT Default value name ' 51WINDOWS '. NET ' for [field name]

Delete default values
ALTER table [table name] DROP CONSTRAINT Default value name

The other is just SQL syntax in ACCESS most of the same

Item, and verify with your own use, verify that adding AutoNumber fields to an Access database is appropriate for: CREATE table datasheet name (ID counter constraint PrimaryKey primary key) needing attention Square is: The second primary has a space in the middle, in addition, the keyword is not case-sensitive. Another method that you have recently discovered is: sql= "CREATE TABLE MYTB (ID autoincrement (25,1) primary key,age int)" sql2= "CREATE TABLE TESTTB (ID autoinc Rement,age Int,email Char, PRIMARY key (ID) "In Access, AutoIncrement is an AutoNumber field, (25,1) is an initial value and a step value, if not written, the default is 1, 1, The primary key specifies a primary key, and the above example, both of the specified methods can be

2. Change field name (column name)

sp_rename ' table name. Original column name ', ' Modified column name ', ' columns '

If the doc_id column name in the Tb_wf_approveinfo table is changed to bind_id:

Sp_rename ' tb_wf_approveinfo.doc_id ', ' bind_id ', ' column '

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.