Y23 Week4 A
Y23 Week4 A
To drop a constraint
ALTER TABLE ITEM DROP CONSTRAINT FK_Item_Part;
CHECK Constraint
• The CHECK constraint is used to limit the value range that can
be placed in a column.
• If you define a CHECK constraint on a single column it allows
only certain values for this column.
Create a CHECK constraint on the "Age" column when the
"Persons" table is created. The CHECK constraint must ensure
that the age of a person must be older than 18.
CREATE TABLE Persons (ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int CHECK (Age>18) );
Dropping a default?
Cannot drop default value instead we set it to NULL.
Alter table tablename modify columnname default NULL;
Note: Default is not a ‘constraint’ as such, hence it does not show up in user_constraints
SELECT * FROM user_cons_columns WHERE table_name = 'MYORDERS';
select data_default from user_tab_columns where table_name = 'MYORDERS';
Data Dictionary
– Central to every Oracle database
– Describes the database and its objects
– Contains read-only tables and views
– Stored in the SYSTEM tablespace
– Owned by the user SYS
– Maintained by the Oracle server
– Accessed with SELECT
10
Data Dictionary
• User-friendly views are available
– e.g. USER_TABLES
• One row for every table in your schema
11
Querying the data dictionary…contd
Prefix Scope
USER User’s view (what is in the user’s schema)
ALL Expanded user’s view (what the user can access)
DBA Database administrator’s view (what is in all users’ schemas)
“USER_TABLES”, is a view on the data dictionary
contains one row for every table owned by you (i.e. created in your schema).
DESC user_tables ^C
SELECT table_name, num_rows from user_tables;
SELECT owner, object_name, object_type FROM ALL_OBJECTS;
Select distinct owner from all_objects;
SELECT owner, table_name FROM all_tables WHERE owner=‘yma'
SQL>desc dba_tables;
SQL> select owner,table_name from dba_tables (user_tables;all_tables)
where tablespace_name =‘USERS’
14
DML – Familiarize with Data Dictionary
Find the name of the table that contains tablespace information for users;
SQL>select * from dict where table_name like 'USER_T%';
Find the names of tablespaces in the user tablespace table.
SQL> select tablespace_name from USER_TABLESPACES;
List all constraints with table name on which they are created - created by you
Oracle - SQL
• Checking the Date Format
select value from V$NLS_Parameters
where parameter=‘NLS_DATE_FORMAT’
• Setting Locality
alter session set NLS_TERRITORY=‘India’
Freeze View (the pin) keeps that object’s tab and information in the window when
you click another object in the Connections navigator; a separate tab and display
are created for that other object.
Refresh .
Insert Row
Delete Selected Row(s) .
Commit Changes
Rollback Change
Sort
Filter predicate
Actions suitable to the table