我需要在Oracle11g的SINGLE查询中找到有关所有用户定义表的以下信息:
到目前为止,我已经设法了:
SELECT table_name FROM user_tables ORDER BY table_name;
TABLE_NAME
---------------
CLIENT
EMPLOYEE
FAULTREPORT
OUTLET
RAGREEMENT
VEHICLE
SELECT table_name, constraint_name, constraint_type
FROM user_constraints
WHERE table_name IN ('CLIENT','EMPLOYEE','FAULTREPORT','OUTLET','RAGREEMENT','VEHICLE')
ORDER BY table_name;
TABLE_NAME CONSTRAINT_NAME C SEARCH_CONDITION
--------------- ------------------------------ - --------------------------------------------------------------------------------
CLIENT CLIENT_CLIENTNAME_NN C clientName IS NOT NULL
CLIENT CLIENT_STREET_NN C street IS NOT NULL
CLIENT CLIENT_CITY_NN C city IS NOT NULL
CLIENT CLIENT_STATE_NN C state IS NOT NULL
CLIENT CLIENT_EMAIL_CK C REGEXP_LIKE(email,'^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,}$','i') AND email IS NOT
NULL
CLIENT CLIENT_PHONE_CK C REGEXP_LIKE(phone,'^(\(\d{3}\))([[:blank:]])\d{3}-\d{4}$|^\d{3}(-)\d{3}(-)\d{4}$
|^\d{10}$')
AND phone IS NOT NULL
CLIENT CLIENT_CLIENTNO_PK P
EMPLOYEE EMPLOYEE_LNAME_NN C lname IS NOT NULL
EMPLOYEE EMPLOYEE_NUM_PK P
EMPLOYEE EMPLOYEE_OUTLET_NUM_FK R
EMPLOYEE EMPLOYEE_FNAME_NN C fname IS NOT NULL
EMPLOYEE EMPLOYEE_DOB_CK C hireDate >= ADD_MONTHS(dob, 216)
EMPLOYEE EMPLOYEE_PHONE_CK C REGEXP_LIKE(phone,'^(\(\d{3}\))([[:blank:]])\d{3}-\d{4}$|^\d{3}(-)\d{3}(-)\d{4}$
|^\d{10}$')
AND phone IS NOT NULL
EMPLOYEE EMPLOYEE_GENDER_CK C gender in ('MALE', 'FEMALE')
FAULTREPORT FAULTREPORT_DATECHECKED_NN C dateChecked IS NOT NULL
FAULTREPORT FAULTREPORT_REPORTNUM_PK P
FAULTREPORT FAULTREPORT_EMPLOYEE_NUM_FK R
FAULTREPORT FAULTREPORT_RENTAL_NUM_FK R
FAULTREPORT FAULTREPORT_LICENSENO_NN C licenseNo IS NOT NULL
OUTLET OUTLET_STREET_NN C street IS NOT NULL
OUTLET OUTLET_NUM_PK P
OUTLET OUTLET_STATE_NN C state IS NOT NULL
OUTLET OUTLET_ZIPCODE_NN C zipCode IS NOT NULL
OUTLET OUTLET_PHONE_CK C REGEXP_LIKE(phone,'^(\(\d{3}\))([[:blank:]])\d{3}-\d{4}$|^\d{3}(-)\d{3}(-)\d{4}$
|^\d{10}$')
AND phone IS NOT NULL
OUTLET OUTLET_CITY_NN C city IS NOT NULL
OUTLET OUTLET_MGR_NUM_FK R
RAGREEMENT RAGREEMENT_CLIENT_NUM_FK R
RAGREEMENT RAGREEMENT_LICENSE_NUM_FK R
RAGREEMENT RAGREEMENT_MILEAGE_CK C mileagebefore < mileageafter
RAGREEMENT RAGREEMENT_INSURANCETYPE_NN C insurancetype IS NOT NULL
RAGREEMENT RAGREEMENT_PK P
RAGREEMENT RAGREEMENT_STARTDATE_NN C startdate IS NOT NULL
RAGREEMENT RAGREEMENT_MILEAGEBEFORE_NN C mileagebefore IS NOT NULL
VEHICLE VEHICLE_DAILYRATE_NN C dailyrate IS NOT NULL
VEHICLE VEHICLE_MODEL_NN C model IS NOT NULL
VEHICLE VEHICLE_MAKE_NN C make IS NOT NULL
VEHICLE SYS_C0010620 C "LICENSENO" IS NOT NULL
VEHICLE VEHICLE_LICENSE_NUM_PK P
VEHICLE VEHICLE_YEAR_CK C EXTRACT(YEAR FROM year) > 2005 AND year IS NOT NULL
VEHICLE VEHICLE_OUT_NUM_FK R
40 rows selected.
有人可以帮帮我吗?谢谢!
答案 0 :(得分:0)
好吧,你可以简单地使用
SELECT table_name, constraint_name, constraint_type
FROM user_constraints
WHERE table_name IN (SELECT table_name FROM user_tables)
ORDER BY table_name;
或
SELECT UT.table_name, UC.constraint_name, UC.constraint_type
FROM user_tables UT
INNER JOIN user_constraints UC ON UT.table_name = UC. table_name
ORDER BY UT.table_name;
这将为您提供有关所有表you own
的详细信息。
现在,如果您想了解您的帐户有权访问的所有表格的详细信息,可以使用
SELECT table_name, constraint_name, constraint_type
FROM user_constraints
WHERE table_name IN (SELECT table_name FROM all_tables)
ORDER BY table_name;
或
SELECT AT.table_name, UC.constraint_name, UC.constraint_type
FROM all_tables AT
INNER JOIN user_constraints UC ON AT.table_name = UC. table_name
ORDER BY AT.table_name;
已编辑:如果您想查看所有列名称和约束详细信息(如果有),请使用以下(未经测试的)
SELECT UTC.table_name
, UTC.column_name
, UC.constraint_name
, UC.constraint_type
FROM USER_TAB_COLUMNS UTC
LEFT JOIN user_constraints UC ON UTC.table_name = UC. table_name
ORDER BY UTC.table_name;