用sql语句添加删除修改字段及一些表与字段的基本操作(Add, delete, modify fields, and some basic operations of tables and fields with the SQL statement).docVIP

  • 9
  • 0
  • 约7.13千字
  • 约 10页
  • 2017-10-07 发布于河南
  • 举报

用sql语句添加删除修改字段及一些表与字段的基本操作(Add, delete, modify fields, and some basic operations of tables and fields with the SQL statement).doc

用sql语句添加删除修改字段及一些表与字段的基本操作(Add, delete, modify fields, and some basic operations of tables and fields with the SQL statement)

用sql语句添加删除修改字段及一些表与字段的基本操作(Add, delete, modify fields, and some basic operations of tables and fields with the SQL statement) Add, delete, modify fields with the SQL statement 1. add fields Alter, table, docdsp, add, dspcode, char (200) 2. delete fields ALTER, TABLE, table_NAME, DROP, COLUMN, column_NAME 3. modify the field type ALTER, TABLE, table_name, ALTER, COLUMN, column_name, new_data_type 4.sp_rename rename Change the name of the user created objects in the current database, such as tables, columns, or user-defined data types. grammar Sp_rename [@objname =]object_name, [@newname =]new_name [[@objtype =]object_type] Such as: EXEC, sp_rename,newname,PartStock 5.sp_help displays some basic information about the table Sp_helpobject_name, such as: EXEC, sp_help,PartStock 6. to determine whether a field PartVelocity exists in a table PartStock If, exists (select * from, syscolumns, where, id=object_id (PartStock), and, name=PartVelocity) PrintPartVelocity exists Else, print,PartVelocity, not, exists Other method: The existence of a judgement table: Select count (*) from, sysobjects, where, type=U, and, name=, your table name Determine the existence of a field: Select count (*) from syscolumns Where id = (select, ID, from, sysobjects, where, type=U, and, name=, your table name) And name = you want to determine the field name A small example -- suppose the table to be processed is called TB -- to determine whether a primary key exists in the column to be added If exists (select 1, from, sysobjects, where, parent_obj=object_id (tb), and, xtype=PK) Begin Print already has a primary key in the table. Columns can only be added to normal columns -- adding columns of type int with default value of 0 Alter table tb add column name int default 0 End Else Begin Print no primary key in table, add primary key column -- adding columns of type int with default value of 0 Alter, table, TB, add, column names, int, primary, key, default, 0 End 7. randomly read several records Acces

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档