sqlsever implements changing field names

New 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 ,
)

Drop table:
Drop table [table name]

Insert data:
INSERT INTO [tablename] (field1,field2) VALUES (100,'51WINDOWS.NET')

Delete data:
DELETE FROM [table name] WHERE [field name]>100

Update data:
UPDATE [table name] SET [field1] = 200, [field2] = '51WINDOWS.NET' WHERE [field3] = 'HAIWA'

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

To drop a field:
ALTER TABLE [table name] DROP COLUMN [field name]

Modify fields:
ALTER TABLE [table name] ALTER COLUMN [field name] NVARCHAR (50) NULL

Rename table: (Access rename table, please refer to article: Rename table in 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')

To drop a constraint:
ALTER TABLE [tablename] DROP CONSTRAINT constraintname

New default value
ALTER TABLE [table name] ADD CONSTRAINT default value name DEFAULT '51WINDOWS.NET' FOR [field name]

DROP DEFAULT
ALTER TABLE [tablename] DROP CONSTRAINT defaultname

In addition, the above is only the syntax of SQL, most of which are the same under ACCESS

Check the items one by one, and verify by yourself, confirm that it is appropriate to add the automatic number field in the access database using the following methods: create table data table name (id counter constraint primarykey primary key) The point to note is: the middle of the second primary There are spaces, and keywords are not case-sensitive. Another method I recently discovered is: sql="create table mytb (id autoincrement(25,1) primary key, age int)" sql2="create table testtb ( id autoincrement, age int, email char, primary key (id))" Among them, in access, autoincrement is the field of automatic numbering type, (25, 1) are the initial value and step value respectively, if not written, the default is 1 , 1, primary key specifies the primary key, in the above example, both methods can be specified

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'

Reprinted from: http://www.jb51.net/article/38312.htm

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325295552&siteId=291194637