3.1 Overview of the SQL Query Language


SQL language의 종류

      • Data-Definition Language :Defining, deleting, modifying relation schemas 데이터 정의언어

      • Data-Manipulation Language : ability to query information from the database 테이터정의언어

      • Integrity
-SQL DDL includes commands for specify integrity constraints that the data must satisfy

      • View definition
-SQL DDL includes commands for dfining views

      • Transaction control

      • Embedded SQL

      • Authorization


3.2 SQL Data Definition

SQL DDL allows the specification of information about relations including

-The schema for each relation
-The domain of values associated with each attribute
-integrity constaints

    • Basic Types in SQL DDL
-Char(n) : n길이의 캐릭터를 고정한다.
-Varchar(n) : 최대 n길이의 캐릭ㅌ를 고정한다.
-Int : 정수
-Smallint : 작은 정수
-Numeric(p,d) :  (??)
-Float(n) : Floating point number

    • Basic Schema Dfinition - Create Table



    • Integrity Constraint in Create Table


    • Drop and Alter Table Constructs
Drop Table student : student table을 지우고 그 내용까지 지운다

Delete from student (Where절 포함 가능) : student table의 내용은 다 지우고 테이블은 남겨둔다

Alter table
-alter talbe r add A D
: A란 이름의 attribute를 R에 추가하는데 D가 A의 Domain이다

-alter table r drop A
: Relation R에서 A란 이름의 attribute를 드롭하는데 not supported by many databases



3.3 Basic Structure of SQL Queries


SQL DML은 Query 정보를 넣고 지우고 업데이트할 수 있게 해준다.

** SQL에서는 대문자 소문자 구별이 없다!! ex) NAME = name = NaMe



    • The Select Clause
ex) SELECT * FROM depart

attribute를 가져온다!! 조건에 맞는

-중복을 제거하려면 : SELECT DINSTINCT depart from instructor  == DISTINCT를 쓰면된다

-중복을 다 보려면 : SELECT ALL depart from instructor == ALL을 쓰면 된다 (이게 기본값이다.)


SELECT cluased에는 + - / * 를 다 쓸수 있다. (*은 전체라는 뜻이다) 



    • The From Clause
lits the relations involved in the query

Corresponds to the cartesian product operation(X말하는 것이다 3 x 3할때) of the relational algebra


    • The Where Clause
specifies conditions that the result must satisfy

Corresponds to the selection predicate of the relational algebra

Comparison은 and or not을 사용할수 있다




  • Joins
2가지 이상의 where문 안에서 나오면 앞에서 relation이름을 언급했으면 뒤에는 안해도된다


    • Natural Join 
위의 Coreect version처럼 자세히 서술해주어야한다. 만약 natural join하는 attribute의 이름이 같다면


3.4 Additional Basic Operations -Rename Operation


SQL allows renaming relations and attributes using the as clause       ex) old-name as new-name



*instructor as T == instructor T


String Operations

SQL includes a string-matching operator for comparisons on character strings. "like"랑 같이 쓰인다ㅡ


-Percent (%) : The % character matches any substring.

-Underscore (_) : The _ character matches any character.




고급 표현

-intro% : intro로 시작하는 모든 String

-%Comp% : Comp가 들어가는 모든 String

-___ : 정확히 3글자인 String

-___% : 최소 3글자인 String


차순

Default : 오름차순

-오름 차순 : asc

-내림 차순 : desc

ex)Order by **** asc



Between

*not Between도 있음


Union


Intersect


Except





문제!!! 풀어보기


'일상 > DataBase' 카테고리의 다른 글

SQL 소개 (2)  (0) 2017.09.28
SQL 공부 1  (0) 2017.09.27
2. Relational Model이란  (0) 2017.09.27
1.데이터베이스(DataBase)란  (0) 2017.09.27

+ Recent posts