Agenda
Inserting values into personal_inf table
view the data from the table
Creating tables using constraints
Inserting values into personal_inf table
Inserting values for all columns in a table
Syntax: SQL> Insert into table_name values (val1, val2…..val_n); — values for all columns
eXAMPLE:
SQL> select * from personal_inf;
no rows selected
SQL> INSERT INTO PERSONAL_INF VALUES (‘GATES’,’JOHN’,25,’01-MAR-14′,’M’);
1 row created.
SQL> SELECT * FROM PERSONAL_INF;
NAME FNAME AGE DOJ G
GATES JOHN 25 01-MAR-14 M
SQL>
Inserting values for selected columns
Syntax: SQL> Insert into table_name(col1,col2…)
values (va1,val2…) — Values for selcted columns
Example: Insert values for name and age
SQL> insert into personal_inf (name,age) values (‘chandu’,30);
1 row created.
SQL> select * from personal_inf;
NAME FNAME AGE DOJ G
GATES JOHN 25 01-MAR-14 M
chandu 30
Inserting values using & : & is used to read/input values at run time
Syntax: SQL> insert into table values (‘&col1′,’&col2’,&col3…)
Example:
SQL> insert into personal_inf
2 values(‘&name’,’&fname’,&age,’&doj’,’&gender’);
Enter value for name: kumar
Enter value for fname: krishna
Enter value for age: 35
Enter value for doj: 20-mar-13
Enter value for gender: m
old 2: values(‘&name’,’&fname’,&age,’&doj’,’&gender’)
new 2: values(‘kumar’,’krishna’,35,’20-mar-13′,’m’)
1 row created.
SQL> /
Enter value for name: swathi
Enter value for fname: guna
Enter value for age: 10
Enter value for doj: 19-mar-15
Enter value for gender: f
old 2: values(‘&name’,’&fname’,&age,’&doj’,’&gender’)
new 2: values(‘swathi’,’guna’,10,’19-mar-15′,’f’)
1 row created.
SQL> select * from personal_inf;
NAME FNAME AGE DOJ G
GATES JOHN 25 01-MAR-14 M
chandu 30
krishna 98
kumar krishna 35 20-MAR-13 m
swathi guna 10 19-MAR-15 f
SQL>