Oacle - ddl 생 성 표 와 관리 표

18961 단어 Oacle
Oacle 기본 Oacle 단일 줄 함수 Oacle 다 중 표 조회 Oacle 그룹 함수 Oacle 서브 조회 Oacle 생 성 표 와 관리 표
--         
/*
	  			         ,      
	  			                
	  			        
	  			       
	   		      

*/
--         
SELECT * FROM user_tables;

--             

SELECT * FROM user_catalog;

--               

SELECT DISTINCT object_type FROM user_objects;


--         --
/*
	1.       
	2.   1-30     
	3.     A-Z a-z 0-9 _ $ #
	4.    
	5.   Oracle   
*/

--      --
/*
	 *       
	VARCHAR2(size)* 	      
	CHAR(size)*			      
	NUMBER(p,s)*			       
	DATE*                 
	LONG						       ,     2G
	CLOB                ,     4G
	RAW(LONG RAW) 	        
	BLOB*						     ,     4G
	BFILE                       ,     4G
	ROWID              
	
*/

--     CREATE TABLE ...              ,  scott      
-- ok
--   1
CREATE TABLE emp1(
	id NUMBER(10), --  10 9
	name VARCHAR2(20), --20   
	salary NUMBER(10,2), --     2 
	hire_date DATE --          
);

SELECT * FROM user_tables WHERE LOWER(TABLE_NAME)  = 'emp1'


--   2(     )
-- ok
CREATE TABLE emp2
AS
SELECT EMPLOYEE_ID id ,LAST_NAME name,HIRE_DATE,SALARY 
FROM EMPLOYEES

SELECT * FROM user_tables WHERE LOWER(TABLE_NAME)  = 'emp2'
--            
SELECT * FROM emp2;

/*
	ALTER TABLE
	1.     
	2.      
	3.           
	4.     
	5.         

*/

--  emp1     
-- ok 
ALTER TABLE emp1
ADD(email VARCHAR2(20))

SELECT * from emp1;

--  emp1 id     15  
ALTER TABLE emp1
MODIFY(id NUMBER(15))


--navicate,desc   ,plsql  


--  emp1 salary     2000

ALTER TABLE emp1
MODIFY(SALARY NUMBER(20,2) DEFAULT 2000)


--  emp2 name    number  

SELECT * FROM emp2
-- column to be modified must be empty to change datatype                 
ALTER TABLE emp2
MODIFY(name NUMBER(20))


--   emp1 email 
-- ok
ALTER TABLE emp1
DROP COLUMN email;


--    emp1   salary    sal

ALTER TABLE emp1
RENAME COLUMN SALARY to sal

--   (    )

--   emp1    

DROP TABLE emp1;

--     ,           
truncate TABLE emp2;

SELECT * FROM emp2;
--   update delete INSERT   sql       。
rollback;


--   

-- 51.          myemp, 
-- 1)      employees    employee_id(id), last_name(name), salary(sal), email   

CREATE TABLE myemp
AS
SELECT EMPLOYEE_ID id,LAST_NAME name,SALARY sal,EMAIL
FROM EMPLOYEES

SELECT * from myemp

-- 2).           employees     ,        

CREATE TABLE myemp2
AS
SELECT EMPLOYEE_ID id,LAST_NAME name,SALARY sal,EMAIL
FROM EMPLOYEES WHERE 1=2 --    

SELECT * from myemp2



-- 52.            

-- 	1).       

ALTER TABLE myemp
add(HIRE_DATE DATE DEFAULT SYSDATE)

SELECT * from myemp

-- 	3).         

ALTER TABLE myemp
RENAME COLUMN tdate to create_date

-- 4).       

ALTER TABLE myemp
DROP COLUMN create_date


-- 53.    (  : truncate),     !!	

truncate TABLE myemp;


-- 54. 
-- 
-- 1).      ,     employees        ,     :  

CREATE TABLE myemp3
AS
SELECT * FROM EMPLOYEES WHERE 1<>1

SELECT * FROM myemp3

-- 2)  employees    80             emp2   : 

SELECT * FROM emp2;
--  *       too many values ,   emp2  EMPLOYEES       
INSERT INTO emp2 SELECT EMPLOYEE_ID id,LAST_NAME name,HIRE_DATE,SALARY FROM EMPLOYEES WHERE DEPARTMENT_ID = 80



/*
1.	   dept1
name	Null?		type
id						Number(7)
name					Varchar2(25)

*/
CREATE TABLE dept1(
id NUMBER(7),
name VARCHAR2(25)
)

SELECT * FROM dept1;

-- 2.	  departments        dept2 

CREATE TABLE dept2
AS
SELECT * FROM DEPARTMENTS

SELECT * FROM dept2;

/*
3.	   emp5
name		Null?		type
id							Number(7)
First_name			Varchar2(25)
Last_name				Varchar2(25)
Dept_id					Number(7)
*/



CREATE TABLE emp5(
 id NUMBER(7),
 FIRST_NAME VARCHAR2(25),
 LAST_NAME VARCHAR2(25),
 dept_id NUMBER(7)
)


--4.	  Last_name      50

ALTER TABLE emp5
MODIFY(LAST_NAME VARCHAR2(50))


-- 5.	   employees  employees2

CREATE TABLE EMPLOYEES2
AS
SELECT * FROM EMPLOYEES

SELECT * FROM EMPLOYEES2

-- 6.	   emp5
SELECT * FROM emp5;
DROP TABLE emp5;


-- 7.	  employees2    emp5

RENAME  EMPLOYEES2 to emp5


-- 8.	  dept emp5     test_column,        

SELECT * FROM dept;

SELECT * FROM emp5;

ALTER TABLE dept 
add(test_column VARCHAR2(20))

ALTER TABLE emp5 
add(test_column VARCHAR2(20))
--desc dept


-- 9.	  dept emp5   test_column      ,    
-- ok
ALTER TABLE DEPT
set unused COLUMN test_column
-- ok
ALTER TABLE DEPT
DROP unused COLUMN
-- ok
ALTER TABLE emp5
set unused COLUMN test_column
-- ok
ALTER TABLE emp5
DROP unused COLUMN

SELECT * FROM dept;

SELECT * FROM emp5;



-- 10.	     emp5    dept_id
--ok
ALTER TABLE EMP5
add(dept_id NUMBER(20))
--ok
ALTER TABLE EMP5
DROP COLUMN dept_id

SELECT * FROM emp5;







좋은 웹페이지 즐겨찾기