Create Table Examples
Easiest example:
SQL> CREATE TABLE libros( titulo VARCHAR2(20));
Tabla creada.
SQL>
a more complex one, with a primary key definition:
CREATE TABLE news
( news_id NUMBER PRIMARY KEY,
news_title VARCHAR2(30),
news_text VARCHAR2(254))
Now we can begin populating the data:
insert data oracle
Also we can alter table estructure:
SQL> create table employee (EMP_NO NUMBER(2), JOB_GRADE VARCHAR2(20), EMP_NAME V
ARCHAR2(20), EMP_SNAME VARCHAR2(20) );
Tabla creada.
SQL>
SQL> ALTER table employee ADD ( EMP_DESC VARCHAR2(50) );
Tabla modificada.
SQL>
We have the following table, and you want to avoid null data at least at the ID COL:
SQL> describe employee;
Nombre ┐Nulo? Tipo
----------------------------------------- -------- -----------------------
EMP_NO NUMBER(4)
JOB_GRADE VARCHAR2(20)
EMP_NAME VARCHAR2(20)
EMP_SNAME VARCHAR2(20)
SQL> alter table employee modify EMP_NO NUMBER(4) NOT NULL;
alter table employee modify EMP_NO NUMBER(4) NOT NULL
*
ERROR en lÝnea 1:
ORA-02296: no se puede activar (SYSTEM.) - se han encontrado valores nulos
SQL>
You can fix removing the null inserted rows:
SQL> select * from employee where EMP_NO is null;
EMP_NO JOB_GRADE EMP_NAME EMP_SNAME
---------- -------------------- -------------------- --------------------
SQL> DELETE from employee where EMP_NO is null;
1 fila suprimida.
SQL> select * from employee where EMP_NO is null;
ninguna fila seleccionada
SQL>
Now you can alter the table.
SQL> ALTER TABLE employee RENAME COLUMN JOB_GRADE to "EMP_GRADE";
Tabla modificada.
SQL>
page revision: 7, last edited: 09 Mar 2012 10:04