




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
SQL command for mysql installation with regular using creating database
Typology: Lecture notes
1 / 8
This page cannot be seen from the preview
Don't miss anything!





http://www.tutorialspoint.com/sql_certificate/using_ddl_statements.htm Copyright © tutorialspoint.com
CREATE TABLE [schema.]table ( { column datatype [DEFAULT expr] [column_constraint] ... | table_constraint} [, { column datatype [DEFAULT expr] [column_constraint] ... | table_constraint} ]...) [AS subquery]
CTAS - Create table using subquery
WHERE department_id= 20 ; Data types
Number data type
Syntax: COLUMN [data type] [NOT NULL] UNIQUE constraint
Syntax:
COLUMN [data type] [CONSTRAINT
Primary Key
Points to be noted -
Syntax:
COLUMN [data type] [CONSTRAINT
CONSTRAINT [constraint name] PRIMARY KEY [column (s)]
Foreign Key
Syntax:
COLUMN [data type] [CONSTRAINT] [constraint name] [REFERENCES] [table name (column name)]
CONSTRAINT [constraint name] [FOREIGN KEY (foreign key column name) REFERENCES] [referenced table name (referenced column name)]
(ccode varchar2( 5 ) CONSTRAINT TEST_FK REFERENCES PARENT_TEST(ccode), ... );
(ccode varchar2( 5 ) CONSTRAINT TEST_FK REFERENCES PARENT_TEST (ccode) ON DELETE CASCADE, ... ); Check constraint
Read Only Tables
Syntax: ALTER TALE [TABLE NAME] READ ONLY ALTER TALE [TABLE NAME] READ WRITE Illustration SQL>CREATE TABLE ORATEST (id NUMBER) SQL>INSERT INTO ORATEST VALUES ( 1 ); SQL>ALTER TABLE ORATEST READ ONLY; SQL> INSERT INTO ORATEST VALUES ( 2 ); INSERT INTO ORATEST VALUES ( 2 )
ERROR at line 1 : ORA- 12081 : update operation not allowed on table "TEST"."ORATEST" SQL> UPDATE ORATEST SET id = 2 ; UPDATE ORATEST SET id = 2
ERROR at line 1 : ORA- 12081 : update operation not allowed on table "TEST"."ORATEST" SQL> DELETE FROM ORATEST; DELETE FROM ORATEST
ERROR at line 1 : ORA- 12081 : update operation not allowed on table "TEST"."ORATEST" SQL> TRUNCATE TABLE ORATEST; TRUNCATE TABLE ORATEST
ERROR at line 1 : ORA- 12081 : update operation not allowed on table "TEST"."ORATEST" SQL> ALTER TABLE ORATEST ADD (description VARCHAR2 ( 50 )); ALTER TABLE ORATEST ADD (description VARCHAR2 ( 50 ))
ERROR at line 1 : ORA- 12081 : update operation not allowed on table "TEST"."ORATEST" SQL> ALTER TABLE ORATEST READ WRITE; Table altered. SQL> DELETE FROM ORATEST;
1 row deleted. DROP TABLE statement
Syntax: DROP TABLE [TABLE NAME] [PURGE]
DROP TABLE emp_new;
DROP TABLE emp_new PURGE; Processing math: 100%