Add fields in SQL (some can only be run in ORACLE)

Source: Internet
Author: User

Add fields in SQL (some can only be run in ORACLE)

[SQL] add field alter table table_name add column_name varchar (200) delete field alter table table_NAME drop column column_NAME modify Field Type alter table table_name alter column column_name new_data_type modify table field length (modify TABLE structure) alter TABLE table_name modify column_name varchar (40); rename sp_rename

 

Change the name of the user-created object (such as a table, column, or user-defined data type) in the current database. Syntax
Sp_rename [@ objname =] 'object _ name', [@ newname =] 'new _ name '[, [@ objtype =] 'object _ type'] -- assume that the table to be processed is named: tb -- determine whether the table to be added has a primary key if exists (select 1 from sysobjects where parent_obj = object_id ('tb') and xtype = 'pk ') the begin print table already has a primary key, and the column can only be added as a common column '-- add a column of the int type, the default value is 0 alter table tb add column name int default 0 end else begin print. No primary key exists in the table. add the primary key column 'query certain fields in the table to record the select count (*) Statement repeatedly (*), column_name from table_name group by column_name having count (*)> 1; query and modify data (for example, change 67001 to 68701,67101 to 68801) select code, ('68 '| (substr (code, 2, 1) + substr (code, 3, 1) | substr (code, 4, 2 )) as code2 from table_name where code like '67 ___ '; update table_name set code = ('68' | (substr (code, 2, 1) + substr (code, 3, 1 )) | substr (code, 4, 2), parentid = '68 'where code like '67 ___';

 


Related Article

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.