Oracle FAQ (1)

Source: Internet
Author: User
Tags how to use sql

Oracle FAQ (1)

01. How can I view oracle version information?

02. How can I view the transaction information locked by the system?

03. How to obtain which users are using the database?

04. What is the maximum number of fields in the data table?
The maximum number of columns in a table or view is 1000.
05. How can I find the database SID?
Select name from v $ database;, you can also directly view the init. ora File
06. How do I query table space information?


07. How do I count the total number of records in two tables?


08. How to obtain the current date of the system. If the number of days is greater than 15, 1 is displayed; otherwise, 0 is displayed?

09. What is the difference between drop user and drop user cascade?
Drop user: only deletes users. drop user × cascade: deletes all tables and views under this user name.
10. Cascade deletion is not set in the database table. How to use SQL statements, for example:
The DEPT_NO field in the EMP table is a foreign key.
The DEPT_NO field in the POS table is a foreign key.
The DEPT table has the DEPT_NO field,
How can I delete the EMP table and the related data in the POS table When deleting the data in the DEPT table?
Method 1: trigger Solution

create or replace trigger delete_deptbefore delete on DEPTfor each rowbegin delete from EMP where DEPT_NO = :old.DEPT_NO; delete from POS where DEPT_NO = :old.DEPT_NO;end;

Method 2: Modify the foreign key settings of the slave table to the "on delete cascade" mode.
A) first query the names of foreign keys in the EMP and POS tables (if you already know the foreign key name, this step can be omitted)
 select CONSTRAINT_NAME,TABLE_NAME from user_constraints where CONSTRAINT_TYPE ='R' and TABLE_NAME in('EMP','POS');

B) Delete the Foreign keys in the EMP and POS tables, and re-establish the foreign key mode that allows cascading deletion.
Alter table EMP drop constraint foreign key name; alter table POS drop constraint foreign key name; alter table EMP add constraint foreign key name foreign key (DEPT_NO) references DEPT (DEPT_NO) on delete cascade; alter table POS add constraint foreign key name foreign key (DEPT_NO) references DEPT (DEPT_NO) on delete cascade;

 


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.