关于创建主键和索引的关系一个小小测试
创建主键时,所对应的列如果没有索引,数据库默认会自动创建一个索引;如果对于列有索引,那么创建主键不会再创建索引。这里要注意,列值必须满足主键的要求(唯一,非空),简单测试如下: SQL create table wxlun_pri(a number); Table created. SQL alter t
创建主键时,所对应的列如果没有索引,数据库默认会自动创建一个索引;如果对于列有索引,那么创建主键不会再创建索引。这里要注意,列值必须满足主键的要求(唯一,非空),简单测试如下:
SQL> create table wxlun_pri(a number);
Table created.
SQL> alter table wxlun_pri add constraint PRIMARY_KEY_REPLY primary key (a); ------创建主键约束
Table altered.
SQL> select index_name from user_indexes where table_name='WXLUN_PRI'; ------默认生成索引
INDEX_NAME
------------------------------
PRIMARY_KEY_REPLY
SQL> alter table wxlun_pri drop constraint PRIMARY_KEY_REPLY;
Table altered.
SQL> select index_name from user_indexes where table_name='WXLUN_PRI';
no rows selected
SQL> create index idx_wxlun_pri on wxlun_pri(a); ------创建一个一般索引,测试有重复值时添加主键约束
Index created.
SQL> insert into wxlun_pri values(1);
1 row created.
SQL> /
1 row created.
SQL> commit;
Commit complete.
SQL> select * from wxlun_pri;
A
----------
1
1
SQL> alter table wxlun_pri add constraint PRIMARY_KEY_REPLY primary key (a); ------原索引有重复值,添加主键约束失败
alter table wxlun_pri add constraint PRIMARY_KEY_REPLY primary key (a)
*
ERROR at line 1:
ORA-02437: cannot validate (WXLUN.PRIMARY_KEY_REPLY) - primary key violated
删除重复值,添加主键约束
SQL> delete from wxlun_pri where rownum1 row deleted.
SQL> commit;
Commit complete.
SQL> select * from wxlun_pri;
A
----------
1
SQL> alter table wxlun_pri add constraint PRIMARY_KEY_REPLY primary key (a); ------成功
Table altered.
SQL> select index_name from user_indexes where table_name='WXLUN_PRI';
INDEX_NAME
------------------------------
IDX_WXLUN_PRI
SQL> drop table wxlun_pri;
Table dropped.
SQL>

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What do you think of furmark? 1. Set the "Run Mode" and "Display Mode" in the main interface, and also adjust the "Test Mode" and click the "Start" button. 2. After waiting for a while, you will see the test results, including various parameters of the graphics card. How is furmark qualified? 1. Use a furmark baking machine and check the results for about half an hour. It basically hovers around 85 degrees, with a peak value of 87 degrees and room temperature of 19 degrees. Large chassis, 5 chassis fan ports, two on the front, two on the top, and one on the rear, but only one fan is installed. All accessories are not overclocked. 2. Under normal circumstances, the normal temperature of the graphics card should be between "30-85℃". 3. Even in summer when the ambient temperature is too high, the normal temperature is "50-85℃

Title: Realme Phone Beginner’s Guide: How to Create Folders on Realme Phone? In today's society, mobile phones have become an indispensable tool in people's lives. As a popular smartphone brand, Realme Phone is loved by users for its simple and practical operating system. In the process of using Realme phones, many people may encounter situations where they need to organize files and applications on their phones, and creating folders is an effective way. This article will introduce how to create folders on Realme phones to help users better manage their phone content. No.

This article will interest you if you are interested in using GIMP for pixel art creation on Windows. GIMP is a well-known graphics editing software that is not only free and open source, but also helps users create beautiful images and designs easily. In addition to being suitable for beginners and professional designers alike, GIMP can also be used to create pixel art, a form of digital art that utilizes pixels as the only building blocks for drawing and creating. How to Create Pixel Art in GIMP Here are the main steps to create pixel pictures using GIMP on a Windows PC: Download and install GIMP, then launch the application. Create a new image. Resize width and height. Select the pencil tool. Set the brush type to pixels. set up

Many friends expressed that they want to know how to create a family in Gree+ software. Here is the operation method for you. Friends who want to know more, come and take a look with me. First, open the Gree+ software on your mobile phone and log in. Then, in the options bar at the bottom of the page, click the "My" option on the far right to enter the personal account page. 2. After coming to my page, there is a "Create Family" option under "Family". After finding it, click on it to enter. 3. Next jump to the page to create a family, enter the family name to be set in the input box according to the prompts, and click the "Save" button in the upper right corner after entering it. 4. Finally, a "save successfully" prompt will pop up at the bottom of the page, indicating that the family has been successfully created.

In iOS17, Apple has added a contact poster feature to its commonly used Phone and Contacts apps. This feature allows users to set personalized posters for each contact, making the address book more visual and personal. Contact posters can help users identify and locate specific contacts more quickly, improving user experience. Through this feature, users can add specific pictures or logos to each contact according to their preferences and needs, making the address book interface more vivid. Apple in iOS17 provides iPhone users with a novel way to express themselves, and added a personalizable contact poster. The Contact Poster feature allows you to display unique, personalized content when calling other iPhone users. you

The "Inaction Test" of the new fantasy fairy MMORPG "Zhu Xian 2" will be launched on April 23. What kind of new fairy adventure story will happen in Zhu Xian Continent thousands of years after the original work? The Six Realm Immortal World, a full-time immortal academy, a free immortal life, and all kinds of fun in the immortal world are waiting for the immortal friends to explore in person! The "Wuwei Test" pre-download is now open. Fairy friends can go to the official website to download. You cannot log in to the game server before the server is launched. The activation code can be used after the pre-download and installation is completed. "Zhu Xian 2" "Inaction Test" opening hours: April 23 10:00 - May 6 23:59 The new fairy adventure chapter of the orthodox sequel to Zhu Xian "Zhu Xian 2" is based on the "Zhu Xian" novel as a blueprint. Based on the world view of the original work, the game background is set

"Operation Delta" will launch a large-scale PC test called "Codename: ZERO" today (March 7). Last weekend, this game held an offline flash mob experience event in Shanghai, and 17173 was also fortunate to be invited to participate. This test is only more than four months away from the last time, which makes us curious, what new highlights and surprises will "Operation Delta" bring in such a short period of time? More than four months ago, I experienced "Operation Delta" in an offline tasting session and the first beta version. At that time, the game only opened the "Dangerous Action" mode. However, Operation Delta was already impressive for its time. In the context of major manufacturers flocking to the mobile game market, such an FPS that is comparable to international standards

Mobile phones are now a necessity for young and middle-aged people. Of course, people of each age group have different needs for mobile phones. As one of the more popular models now, RedmiK70Pro has a very diverse range of functions and services that can meet the needs of consumers of different ages. How to set the return key and home key on Redmi K70Pro? You also need to understand it clearly. Only after you understand it can you decide whether to buy this mobile phone. Then follow the editor to take a look at the following content! How to set the return key and home key on Redmi K70Pro? To access your phone's settings menu, you can open the settings interface by pulling down the notification shade or looking for the settings icon on your home screen. In the settings interface, find and click "Button" or "Navigation Bar"
