Oracle设置和删除不可用列 1、不可用列是什么? 就是表中的1个或多个列被ALTER TABLEhellip;SET UNUSED 语句设置为无法再被程序
Oracle设置和删除不可用列
1、不可用列是什么?
就是表中的1个或多个列被ALTER TABLE…SET UNUSED 语句设置为无法再被程序利用的列。
2、使用场景?
If you are concerned about the length of time it could take to drop column data from
all of the rows in a large table, you can use the ALTER TABLE…SET UNUSED statement.
如果你担心从一个大表中删除一列可能花费大量时间,你可以使用ALTER TABLE…SET UNUSED语句。
如果你有这个需求,要删除某一个读写频繁的大表上的某些列,
如果你在业务繁忙时间直接执行 ALTER TABLE ABC DROP (COLUMN);
可能会收到 ORA-01562 - failed to extend rollback segment number string,
这是因为在这个删除列的过程中你可能会可能消耗掉整个回滚表空间,造成这样的错误出现。
3、使用理由(原理和优势)?
3.1 设置不可用列
This statement marks one or more columns as unused, but does not actually remove
the target column data or restore the disk space occupied by these columns。
a column that is marked as unused is not displayed in queries or data dictionary
views, and its name is removed so that a new column can reuse that name.
该语句可将一个或多个列标识为不可用,但实际上并不是移除了列数据或回收了这些列占用的空间。
一个不可用列不会在查询或数据字典视图中显示, 其列名被删除以至于新增的列可以重用其列名。
In most cases, constraints, indexes, and statistics defined on the column are also removed.
在多数情况下,列上的约束,索引,和统计信息也被移除。
The exception is that any internal indexes for LOB columns that are marked unused are not removed.
例外情况是被标识为不可用的LOB列的内部索引不会被移除。
3.2 删除不可用列
ALTER TABLE…DROP UNUSED COLUMNS 语句仅针对不可用列,用于正式删除被标识为不可用的列(物理上删除列同时回收被占用的空间)。
In the ALTER TABLE statement that follows, the optional clause CHECKPOINT is specified.
This clause causes a checkpoint to be applied after processing the specified number of
rows, in this case 250. Checkpointing cuts down on the amount of undo logs
accumulated during the drop column operation to avoid a potential exhaustion of
undo space.
在接下来的ALTER TABLE语句中个,指定了可选条件 CHECKPOINT。
这个条件将在处理过程达到指定行数时触发一个检查点,此处为250. 检查点削减了在删除列操作中累积的undo logs的数量,从而避免潜在的undo空间耗尽。
ALTER TABLE hr.admin_emp DROP UNUSED COLUMNS CHECKPOINT 250;
4、使用限制?
1)无法删除属于 SYS 的表中的列
2)
5、语法结构?
ALTER TABLE…SET UNUSED(C1,C2..)
ALTER TABLE…DROP UNUSED COLUMNS
例如:
ALTER TABLE hr.admin_emp SET UNUSED (hiredate, mgr);
ALTER TABLE hr.admin_emp DROP UNUSED COLUMNS;
5、数据字典
USER_UNUSED_COL_TABS
ALL_UNUSED_COL_TABS
DBA_UNUSED_COL_TABS
SELECT * FROM DBA_UNUSED_COL_TABS;
OWNER TABLE_NAME COUNT
--------------------------- --------------------------- -----
HR ADMIN_EMP 2–count列代表不可用列数量
6、使用案例?
SCOTT@orcl> create table tmp_all_objects
2 AS
3 SELECT object_id, object_name
4 from dba_objects
5 ;
表已创建。SYS@orcl> exec show_space('TMP_ALL_OBJECTS','SCOTT');
Unformatted Blocks .................... 0
FS1 Blocks (0-25) .................... 0
FS2 Blocks (25-50) .................... 0
FS3 Blocks (50-75) .................... 0
FS4 Blocks (75-100) .................... 0
Full Blocks .................... 352
Total Blocks ........................... 384
Total Bytes ........................... 3,145,728
Total MBytes ........................... 3
Unused Blocks........................... 18
Unused Bytes ........................... 147,456
Last Used Ext FileId.................... 4
Last Used Ext BlockId................... 14,592
Last Used Block......................... 110
PL/SQL 过程已成功完成。
SYS@orcl> DESC DBA_UNUSED_COL_TABS
名称 是否为空? 类型
---------------------------------------- -------- ---------------------------
OWNER NOT NULL VARCHAR2(30)
TABLE_NAME NOT NULL VARCHAR2(30)
COUNT NUMBER
SYS@orcl> SELECT * FROM DBA_UNUSED_COL_TABS;
未选定行
SCOTT@orcl> ALTER TABLE TMP_ALL_OBJECTS SET UNUSED(OBJECT_NAME);
表已更改。
SYS@orcl> SELECT * FROM DBA_UNUSED_COL_TABS;

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver CS6
Visual web development tools