DDL (Data Definition Language)

396 단어·1 분·원문(.md)

  • DDL (Data Definition Language) is a language for defining data, or more precisely, 'a language for defining containers that hold data,' and these containers are referred to as objects in a DBMS.
  • The targets, or object types, that can be defined through DDL are as follows.
DDL TargetDescription
SchemaData structure considering DBMS characteristics and implementation environment, intuitively understood as a single database.
DomainInformation specifying an attribute's data type, size, constraints, etc., understood as the range of values an attribute can hold.
TableData storage space
ViewA virtual logical table derived from one or more physical tables
IndexData structure to speed up searches

DDL Commands #

CREATE #

  • Creates database objects

New Creation

CREATE TABLE <table_name> (
  열이름 데이터 타입 [DEFAULT ][NOT NULL]
  [PRIMARY KEY ( 리스트)]
  {[FOREIGN KEY( 리스트) REFERENCES 테이블 이름 [( 이름)]
  [ ON DELETE 옵션]
  [ ON UPDATE 옵션] ]} * 
  [CHECK (조건식) | UNIQUE (열이름)] ]};
)

Creating a table using information from another table

CREATE TABLE 테이블이름 AS SELECT '

ALTER #

  • Modifies database objects
  1. Add column
ALTER TABLE 테이블이름 ADD 열이름 데이터 타입
  1. Change column data type
ALTER TABLE 테이블이름 MODIFY 열이름 데이터타입 
  1. Delete column
ALTER TABLE 테이블이름 DROP 열이름

DROP , TRUNCATE #

  • DROP : Deletes database objects
  • TRUNCATE : Deletes the contents of a database object, but retains the table structure
  1. Delete table
DROP TABLE 테이블이름
  1. Delete table contents
TRUNCATE TABLE 테이블이름
  1. Rename table
RENAME TABLE 이전 테이블이름 TO 새로운 테이블이름
ALTER TABLE 이전 테이블이름 RENAME 새로운 테이블 이름

Data Types #

  • CHAR : Fixed-length string data type
  • VARCHAR : Variable-length string data type
  • INT : Data type used for numbers
  • FLOAT : Floating-point data type
  • DATE : Data type used for dates
정보처리/ddl.md