用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)
用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
您可能关注的文档
- 浅谈论声乐作品分析中的歌词理解(On the understanding of lyrics in the analysis of vocal music works).doc
- 浅谈语文教学如何激发学生兴趣(How to stimulate students' interest in Chinese Teaching).doc
- 浅谈财政投资评审从定额计价向工程量清单计价的转换(Discussion on the conversion of financial investment evaluation from quota valuation to engineering quantity list valuation).doc
- 浅谈钢筋工程的监理(Elementary introduction to supervision of steel bar project).doc
- 浅谈青年教师成长中的浮躁心理问题及对策(On the impetuous psychological problems and Countermeasures in the growth of young teachers).doc
- 浅谈钻孔灌注桩的施工质量控制().doc
- 浅谈顾客心理和商品视觉陈列(Discussion on customer psychology and merchandise visual display).doc
- 浅谈高层建筑外墙防渗漏施工技术(Construction technology of exterior wall seepage prevention for high rise building).doc
- 测井(Logging).doc
- 浅谈科技场馆人员微笑礼仪服务(Talking about the service of smiling and courtesy in science and technology venues).doc
- 用光技巧 如何善用闪光灯(How to use flash with light technique).doc
- 用六个步骤建立平衡计分卡(Establish a balanced scorecard with six steps).doc
- 用友u8 all-in-one彰显一体化与平台化(UF U8 all-in-one highlight integration and platform).doc
- 用友软件u8系统用户操作手册(UFIDA U8 system user manual).doc
- 用夸奖激励员工(Encourage employees with compliments).doc
- 用夸奖去激励员工——马上可以去做的具体方法!(Use compliments to motivate employees - the right way to do it right away!).doc
- 用工荒转折点下的契机(Labor shortage a turning point).doc
- 用差异化策略创新包装企业培训(Innovation of packaging enterprise training by differentiation strategy).doc
- 用心画爱的圆(Draw a circle of love with your heart).doc
- 用户信息反馈讨论(User information feedback discussion).doc
最近下载
- 超星尔雅学习通《古典诗词鉴赏(复旦)》章节测试答案.pdf VIP
- 《中外建筑史(第2版)》高职全套教学课件.pptx
- 人工智能通识(微课版)课件 第3章 人工智能助力职场.pptx
- 自然语言处理:大模型理论与实践 课件 chapter-13 探讨.pptx
- 分子生物学分子生物学 (3).ppt VIP
- 2022年期末考试六年级上册科学试题.docx VIP
- 氢氧化钾安全技术说明书MSDS.pdf VIP
- 2025教资考试-小学综合素质模拟题(一)试题附答案.pdf VIP
- 吉利星越_汽车保养手册用户服务指南车辆维护保修说明书电子版.pdf VIP
- 高速铁路牵引供电统6C系统运用现状分析.ppt VIP
原创力文档

文档评论(0)