0% found this document useful (0 votes)
3 views3 pages

Primary Key:: Insertion Data Into Table

The document explains the concepts of primary keys and foreign keys in database tables. It provides syntax for creating tables with primary keys and foreign keys, along with examples of inserting data and the expected outputs. Additionally, it highlights error messages that occur when constraints are violated during data insertion.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Primary Key:: Insertion Data Into Table

The document explains the concepts of primary keys and foreign keys in database tables. It provides syntax for creating tables with primary keys and foreign keys, along with examples of inserting data and the expected outputs. Additionally, it highlights error messages that occur when constraints are violated during data insertion.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Primary key:

Primary key is a minimal set of attributes (columns) in a table that uniquely identifies
tuples (rows) inthat table.
Syntax:
CREATE TABLE <table_name>(<column_name><data_type> primary key,
<column_name2><data_type> CHECK <CONDITION>,..........);
Example:
create table employ(eno number(5) primary key,ename char(30),sal number(10));
Output:
Table created.
Insertion data into table:
insert into employ values(101,'kiran',7000);
Output: 1 row(s) inserted.
insert into employ values(102,'raju',9000);
Output: 1 row(s) inserted.
insert into employ values(101,'raju',9000);
Output:ORA-00001: unique constraint (SYSTEM.SYS_C004047) violated
Displaying data:
Select * from employ;
Output:

FOREIGN KEY:
Foreign keys are the columns of a table that points to the primary key of another table.
They act as a cross-reference between tables.
Syntax:
CREATE TABLE <table_name> (<column_name><data_type>references
tablename(column name),<column_name2><data_type>.........);
Example:
Create table empdept(eno number(5) references employ(eno),dname char(15));
Output: Table created.
Insertion data into table:
insert into empdept values(101,'hr');
Output:1 row(s) inserted.
insert into empdept values(102,'accounts');
Output:1 row(s) inserted.
insert into empdept values(103,'hr');
Output:ORA-02291: integrity constraint (SYSTEM.SYS_C004050) violated - parent key
not found.
Displaying data:
Select * from empdept;
Output:

You might also like