본문 바로가기

Contact English

【데이터베이스】 12-1강. SQL example

 

12-1강. SQL example

 

추천글 : 【데이터베이스】 12강. SQL 


 

● CREATE SCHEMA schema_name AUTHORIZATION user_id;

 

● CREATE DOMAIN domain_name data_type

[DEFAULT default_value]

[CONSTRAINT VALID-domain_name CHECK(□, △, ○)];

 

● CREATE TABLE table_name

(attribute_name date_type [NOT NULL], ···,

PRIMARY KEY(primary_key_attribute),

UNIQUE(alternate_key_attribute,···),

FOREIGN KEY(foreign_key_attribute,···)

REFERENCES reference_table(reference_table_primary_key),

CONSTRAINT constraint_condition CHECK(conditional_equation));

 

● CREATE  VIEW view_name [(attribute1, ···)]

 

AS SELECT_sentence;

 

 

● CREATE [UNIQUE] INDEX index_name

ON table_name(attribute_name [ASC | DESC])    // if omited, the default is ASC

[CLUSTER];

 

● ALTER TABLE table_name ADD attribute_name data_type [DEFAULT default_value];

ALTER TABLE table_name ALTER attribute_name [SET DEFAULT default_value];

ALTER TABLE table_name DROP attribute_name [CASCADE];

 

● DROP SCHEMA schema_name [CASCADE | RESTRICTED];

DROP DOMAIN domain_name [CASCADE | RESTRICTED];

DROP TABLE table_name [CASCADE | RESTRICTED];

DROP VIEW view_name [CASCADE | RESTRICTED];

DROP INDEX index_name;

 

● SELECT predicate [table_name.]attribute1 [As attribute1_nickname], [table_name.]attribute2, ···

FROM table1, table2, ···

[WHERE condition]

[GROUP BY attribute1, attribute2, ···]    // when representing the result w/ grouping by attribute#

[GROUP BY attribute1, attribute2, ···]    // generally used w/ group function (ex. avg, sum, max)

[HAVING condition]

[ORDER BY attribute [ASC | DESC]];

 

● INSERT INTO table_name (attribute1, attribute2, ···)

VALUES (data1, data2, ···);

 

● DELETE FROM table_name

WHERE condition;

 

● UPDATE table_name

SET attribute1 = data1, attribute2 = data2, ···

WHERE condition;

 

입력: 2017.08.19 08:27