Displaying the constraints in a table

谁都会走 提交于 2019-12-01 00:01:17

问题


Hello I am trying to display the constraints in one of my tables but for some reason I get the message no rows selected. Noted below is the table I have created.

Create table Teams (
   TeamID varCHAR2(4) constraint Teams_TeamID_PK Primary Key,
   TeamName VARCHAR2(40) 
);

This is the code I am using to show my constraints.

SELECT constraint_name, 
       constraint_type,
       search_condition
  FROM USER_CONSTRAINTS
 WHERE table_name = 'Teams';

I am a rookie so I want to make sure I understand what is wrong. I have tried to drop the table thinking that my constraints did not take - I did not, nor did I receive any errors when I created the table and I am referencing TeamID in another table. So when I try to drop the table I get an error message when is what I was hoping for.


回答1:


select dbms_mview.get_ddl('TABLE',USER,'TEAMS') from dual;



回答2:


Try this:

SELECT constraint_name, 
       constraint_type,
       search_condition
  FROM USER_CONSTRAINTS
 WHERE table_name = 'TEAMS';

Unless double-quoted when created, all object names in Oracle are upper case.




回答3:


I personally use:

SELECT * FROM all_constraints WHERE Table_Name = <TableName>;



回答4:


Use the following code:

show create table table_name;



回答5:


If you prefer the CamelCase names, your create table script should have been:

Create table "Teams" ( 
  "TeamID" varCHAR2(4) constraint "Teams_TeamID_PK" Primary Key, 
  "TeamName" VARCHAR2(40)  
); 

Without double-quotes Oracle helpfully converts all identifiers to uppercase :)




回答6:


Type the table name in upper case in where clause within the single quotes.

e.g. WHERE table_name = 'TEAMS';



来源:https://stackoverflow.com/questions/1837793/displaying-the-constraints-in-a-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!