2. First, modify the field name and use the sql statement: "execute sp_rename" table name. Field name',' new field name' ",as shown in the figure.
Example of modification: execute sp _ rename' student.name',' namenew'
3. Then modify the type and use the sql statement: "alter table"' table name' alter column'' field name? The type is not empty.
Modification example: alter table? Student? Change columns? nameNew int? Not empty
Extended data
Alter statements are often used when modifying the table structure of Sql Server. Here are some commonly used Alter statements.
1. Add a field to the table
Alter table[ table name ]add[ column name] type
2. Delete fields
Change table [table name]? Delete column [column name]
3. Modify the field type in the table (you can modify the column type whether the column is empty or not).
Alter table[ table name ]alter column[ column name] type
4. Add a primary key
Alter table [table name] Add constraint [? Constraint Name] Primary Key ([Column Name])
5. Add a unique constraint
Alter table [table name] Add constraint [? Constraint Name] Unique ([Column Name])
6. Add the default value of a column in the table.
Alter table[ table name ]add constraint[ constraint name ]default for[ column name].
7. Add constraints
alter table[table name]add constraint[constraint name]? Check (content)
8. Add foreign key constraints
alter table[table name]add constraint[constraint name]? The foreign key (column name) refers to another table name (column name).
9. Delete constraints
Alter table[ table name ]drop constraint[ constraint name]?
10, rename table
Exec sp_rename '[ original table name]',' [new table name]'
1 1. Rename the column name
Execsp _ rename "[table name]". [column name]',' [table name]. [New Column Name]'
12. Delete the primary key and indexes on it.
Alter table table_name delete constraint clusteredName
References:
Baidu Experience-How does -sql server change field names and types with statements?