SlideShare a Scribd company logo
6.Creating Database 데이터 저장 방식 데이터베이스 생성하기 데이터베이스 조작하기 파일그룹 생성 데이터 타입 생성 테이블 생성 스크립트 이용 도서관 데이터베이스 Practice
데이터 저장 방식 Extent  (8 contiguous 8-KB pages) Page (8 KB) Tables,Indexes Data Database Data (file) .mdf  or  .ndf Log (file) .ldf Max  row size = 8060 bytes
보충설명 -  모든 데이터베이스는 주 데이터 파일 (.mdf) 를 가지고 하나  또는 그 이상의 로그파일 (.ldf) 을 가진다 .  데이터베이스는 두번 째 데이터베이스 파일 (ndf) 을 가질 수 있다 . -  데이터베이스를 만들면  model  데이터베이스의 시스템 테이블 이 데이터베이스로 복사된다 .  따라서 데이터베이스는 최소한 model  데이터베이스보다 크거나 같게 된다 . -Row cannot span pages.  따라서 하나의 행에 넣을 수 있는 데이 터의 최대 크기는  8060 바이트이다 .( 오버헤드를 제외한 수치 ) - 테이블과 인텍스는  extent 에 저장되는대  extent 는  8 개의 연속 적인 페이지 따라서  64KB 이다 .
데이터베이스 생성하기 데이터베이스 정의 데이터베이스 이름 데이터베이스 크기 데이터베이스가 저장될 파일 CREATE DATABASE sample ON   PRIMARY ( NAME=sample_data,    FILENAME='c:\mssql7\data\sample.mdf',    SIZE=10MB, MAXSIZE=15MB, FILEGROWTH=20%)  LOG ON    ( NAME=sample_log,    FILENAME='c:\mssql7\data\sample.ldf',    SIZE=3MB, MAXSIZE=5MB, FILEGROWTH=1MB)
데이터베이스 옵션 선택 데이터베이스 옵션 선택 자주 사용되는 옵션 dbo use only read only trunc. log on chkpt. autoshrink 데이터베이스 옵션 보기 sp_dboption, sp_helpdb,  sp_spaceused
자주 사용되는 옵션 dbo use only -  데이터베이스의 사용을 데이터베이스 소유주로 제한한다 . Read only -  데이터베이스를 읽기전용으로 정의한다 . Select into/bulkcopy -  데이터베이스로 하여금 로그를 하지 않는 작업을 수행하도록 한다 . Trunc.log on chkpt -  체크포인트 프로세서 후의 로그를 지운다 . Autoshink -  데이터베이스 크기가 자동적으로 줄어들것인지를    결정한다 . Single user -  데이터베이스에 대한 접근을 한번에 한사람으로   제한한다 .
데이터베이스 조작하기 데이터와 로그 파일의 크기 증가 조절하기 트랜잭션 로그 확대 데이터베이스나 파일 줄이기 데이터베이스 제거
데이터와 로그 파일의 크기 증가 조절하기 ALTER DATABASE sample   MODIFY FILE ( NAME = 'sample_log',   SIZE = 10MB) GO ALTER DATABASE sample ADD FILE  (NAME = sample_data2 , FILENAME='c:\mssql7\data\sample2.ndf', SIZE=10MB , MAXSIZE=20MB) GO 7 MB 3 MB
보충설명 - ALTER DATABASE 문을 사용하기 위해서는  master database 를  사용하고 있어야 한다 . - 데이터베이스의 크기를 조절하는 방법 1.  데이터베이스와 로그파일이 자동으로 증가하도록 한다 . 2.  현재 존재하는 데이터베이스와 로그파일의 현재크기와 최대 크기를 수동으로 증가 시킨다 . 3.  수동으로 두 번째 데이터베이스와 로그파일을 추가한다 .
Transaction Log 가 작동하는 원리 Data modification is  sent by application 1 Disk Modification is recorded  in transaction log on disk 3 Data pages are located in,  or read into, buffer cache  and modified 2 Buffer Cache Disk Checkpoint writes  committed  transactions to database 4
트랜잭션 로그 확대 로그 감시 필요 시 로그 크기 확대 과부하 로그 생성 감시 다량의 데이터를 인덱스 테이블에 로딩 시 큰 트랜잭션 이미지나 텍스트 처리 수행 시
데이터베이스나 파일 줄이기 전체 데이터베이스 줄이기 데이터베이스내의 데이터 파일 줄이기 데이터베이스를 자동적으로 줄이기 DBCC SHRINKDATABASE (sample, 25) DBCC SHRINKFILE (sample_data, 10)
데이터베이스 제거 제거 방법 SQL Server Enterprise Manager DROP  문장 데이터베이스 제거 시 제한 사항 복구 시 (Restored) 사용자 접근 시  (connecting to it) 복제에서 출판시 (Publishing) DROP DATABASE northwind, pubs
Leveraging the Windows NT Server Fault Tolerance Using Disk Striping (RAID Level 0) Using Disk Mirroring (RAID Level 1) Using Disk Striping with Parity (RAID Level 5) Using RAID with SQL Server
파일그룹 생성 northwind Database Northwnd.mdf C:\ Ordhist1.ndf Ordhist2.ndf D:\ Northwnd.ldf C:\ Default Filegroup OrderHistoryGroup sys... sys... sysusers sysobjects ... orders customers products ordhistyear2 ordhistyear1
보충설명 -1 - Filegroups are named collections of files  -With filegroups. You can locate specific objects on a specific file Types of filegroups -The default filegroup : contains the primary data file and any other  files that are not part of another filegroup. All system tables and all  tables and indexes for which a filegroup was not specified upon  creation are placed in the default filegroup -User-defined filegroup: which are any  filegroups that are specified by  using the FILEGROUP keyword in an ALTER DATABASE
보충설명 -2 예제 ) The following example creates a user-defined filegroup in thenorthwind database and adds a secondary data file to the user-defined filegroup ALTER DATABASE northwind ADD FILEGROUP orderhistorygroup GO ALTER DATABASE northwind ADD FILE ( NAME = ‘ordhistyear1’, FILENAME = ‘c:\mssql7\data\ordhist1.ndf’,   SIZE - 5 MB), TO FILEGROUP orderhistorygroup GO
데이터 타입 생성 시스템 지원 데이터 타입 사용자 정의 데이터 타입의 생성과 제거
시스템 지원 데이터 타입 시스템 지원 데이터 타입 분류 이진  (Binary) - binary[ ], varbinary[ ] 문자형  (Character) - char[ ], varchar[ ] 유니코드 문자  (Unicode character)-nchar[ ], nvarchar[ ] 날짜와 시간  (Date and time) - Datetime, samlldatetime Exact  와  Approximate Numeric Data Exact Numeric Data - decimal[(p[,s])], numeric[p[,s]] Approximate - float[(n)], real
추가적인 시스템 제공 데이터 타입 Global identifier  uniqueidentifier Integer    int Monetary    money, smallmoney Special   bit, cursor, sysname, timestamp Text and Image  text, image Unicode text  ntext
사용자 정의 데이터 타입의 생성과 제거 생성 제거 사용자 정의 데이터 타입 생성 지침 EXEC  sp_addtype isbn, 'smallint’, 'NOT NULL' EXEC  sp_addtype zipcode, 'char(10)' EXEC  sp_addtype longstring, 'varchar(63)' EXEC  sp_droptype isbn
사용자 정의 데이터 타입 생성 지침 -  만약 칼럼의 길이가 변한다면 변하는 데이터 타입을 사용하라 . 예를 들면 ,  이름의 리스트를 만들어야 한다면 ,  고정된  char  보다 변할 수 있는  varchar  타입을 사용한다 . -  숫자 데이터 타입에 대해서는 요구되는 크기와 정확도를 고려 한다 .  일반적으로는  decimal 을 사용한다 . - 저장해야 되는 데이터가  8000 바이트보다 크다면 , text 나  image 테이터 타입을 사용하라 .(2GB 까지 저장가능 ).
테이블 생성 테이블 생성과 제거 열의 추가와 제거(SQL Server 7.0의 추가기능) 열 값의 생성
테이블 생성과 제거 Column name Data type NULL or NOT NULL CREATE TABLE member ( member_no lastname firstname middleinitial photograph ) member_no shortstring shortstring letter image NOT NULL, NOT NULL, NOT NULL, NULL, NULL
테이블의 생성 -  하나의 데이터베이스에  20 억 개의 테이블을 만들 수 있다 . -  테이블 당  1024 개의 칼럼을 가질 수 있다 . -NOT NULL 이  SQL Server 의 디폴트이다 . 테이블의 제거 - 테이블을 제거하기 전에 테이블과 다른 객체들과의 의존관계를  제거해야 한다 .  의존관계를 알아 볼려면  sp_depends  시스템 프로 시져를 사용한다 . Syntax DROP TABLE table_name [,…n]
열의 추가와 제거 ALTER TABLE sales   ADD customer_name char(30) null ALTER TABLE sales   DROP COLUMN sales_date 제거 Commission Sales_amount Sales_date Customer ID Customer_name
열 값의 생성 IDENTITY 속성 이용 Seed 값 설정 increment value 설정 가장 최근의 값 이용 :  @@identity NEWID 함수와 식별자 데이터 타입의 이용 글로벌한 유일 값 DEFAULT 제약 이용
IDENTITY  속성 이용하기 문법 CREATE TABLE table (column_name data_type [IDENTITY [seed [ , increment] NOT NULL) -  오직 하나의 칼럼만이 허용된다 . -  갱신될 수 없다 . - NULL  값을 허용하지 않는다 . - integer(int, smallint, tinyint), numeric, decimal  형과 사용되어야 한다 . -IDENT_SEED: seed,  시작값을 알려 준다 . -IDENT_INCR:  증가값을 알려 준다 .
예제 ) In this example, the customer table customer ID column is created with a uniqueidentifier data type, with a default value generated by the NEWID function. A unique value for the cust_id column  will be generated for each new and existing row CREATE TABLE customer (cust_id uniqueidentifier  NOT NULL DEFAULT  NEWID(), Cust_name char(30)  NOT NULL)
Transact-SQL  스크립트를 이용한 스키마 생성 백업용 스크립트 이용 개발용 스크립트를 생성하거나 업데이트 테스트용 혹은 개발용 환경의 생성 새로운 직원을 훈련 생성할 수 있는 것 전체 데이터베이스 테이블 스키마 테이블과 인덱스 스키마 스크립트 이용
권장 사항 Place Database and Transaction Log on Separate Physical Disks Disable Write Caching on Disks  Specify Maximum Size When You Use Automatic File Growth Back Up master Database After You Create or Modify a Database Generate Scripts to Re-create Database and Database Objects
데이터 베이스 예제 - 도서관 도서관 데이터베이스 생성
스키마 isbn copy_no title_no on_loan copy isbn title_no translation cover loanable item title_no title author synopsis title member_no street city state zip phone_no eaxpr_date adult isbn member_no log_date remarks reservation member_no lastname firstname middleinitial photograph member member_no adult_member_no birth_date juvenile isbn copy_no title_no member_no out_date due_date loan isbn copy_no out_date title_no  member_no due_date in_date fine_assessed fine_paid fine_waived remarks loanhist
Member Information juvenile member_no adult_member_no birth_date PK, FK FK, NN NN 3 4 5 2 1 1 Jun 01 1980 Mar 01 1978 Nov 05 1982 adult member_no street city state zip PK,FK NN NN NN NN 1 2 6 Elm St Bowery Ave Bowery Ave Seattle Seattle Kent WA WA WA 98022 98022 98206 phone_no NULL (206)555-1212 NULL expr_date NN Jun 06 1992 Aug 07 1992 Mar 03 1993 member member_no lastname firstname middleinitial photograph PK NN NN 1 2 3 4 5 6 Anderson Barr Barr Anderson Anderson Henson Andrew Andrew Bill Bill Sally Jack A R NULL B A NULL ~~~ ~~~ ~~~ ~~~ ~~~
Item Information title_no  copy_no on_loan isbn  1 1 2 3 4 4 Y Y N Y Y Y 1 2 1 1 1 2 1 1 2 3 4 4 copy FK, NN NN PK, FK PK PK FK, NN isbn  title_no  translation cover  loanable 1 2 3 4 5 1 2 3 4 2 English French French NULL English softback NULL hardback hardback softback Y N Y NULL Y item PK NN title title_no  title author NN synopsis 1 2 3 4 Gone With the Wind Color Purple Hotel Winnie the Pooh Mitchell Walker Hailey Milne ~~~ ~~~ ~~~
Loan Information reservation isbn member_no log_date PK,FK PK, FK 1 1 4 2 3 3 3/7/1992 NULL 3/17/1992 remarks ~~~ NULL ~~~ loan isbn copy_no title_no member_no out_date PK,FK1 PK, FK1 FK,NN FK, NN PK, NN 1 4 4 3 1 1 1 2 1 2 1 4 4 3 1 1 1 2 3 1 03/18/92 03/15/92 03/17/92 03/18/92 03/15/92 due_date NN 03/29/92 03/29/92 04/01/92 04/02/92 03/29/92 loanhist isbn copy_no out_date PK,FK1 PK, FK1 NN 1 2 2 1 1 1 1 1 2 1 10/13/91 07/07/91 10/13/91 11/06/91 10/30/91 title_no FK,NN 1 2 2 1 1 member_no FK, NN 4 2 4 3 1 due_date 10/27/91 07/21/91 10/27/91 11/20/91 11/13/91 in_date 10/26/91 NULL 10/28/91 11/14/91 11/15/91 fine_assessed 0.00 0.10 0.00 0.20 0.00 fine_paid 0.00 0.00 0.00 0.20 0.00 fine_waived 0.00 0.10 0.00 0.00 0.00 remarks ~~~ ~~~ ~~~ ~~~
데이터베이스 만들기  (1) DB 의 이름을 적는다 .
데이터베이스 만들기  (2) 트랜잭션로그를  적는다 .
테이블 만들기

More Related Content

PDF
Hive 입문 발표 자료
PPTX
20140522 uc집계 정민철_발표자료_최종
PDF
Tableau TD3 Korean Manual
PDF
(140625) #fitalk sq lite 삭제된 레코드 복구 기법
PPTX
검색엔진이 데이터를 다루는 법 김종민
PDF
하둡 좋은약이지만 만병통치약은 아니다
PDF
하둡 HDFS 훑어보기
PPTX
Mongo DB 완벽가이드 - 4장 쿼리하기
Hive 입문 발표 자료
20140522 uc집계 정민철_발표자료_최종
Tableau TD3 Korean Manual
(140625) #fitalk sq lite 삭제된 레코드 복구 기법
검색엔진이 데이터를 다루는 법 김종민
하둡 좋은약이지만 만병통치약은 아니다
하둡 HDFS 훑어보기
Mongo DB 완벽가이드 - 4장 쿼리하기

What's hot (20)

PDF
(150124) #fitalk advanced $usn jrnl forensics (korean)
PDF
PDF
리눅스 간단 강의 2강
PDF
리눅스 간단 강의 4강
PPTX
하둡 타입과 포맷
PDF
Soma search
PDF
Hadoop발표자료
PDF
엘라스틱서치, 로그스태시, 키바나
PDF
hadoop ch1
PPTX
Mongo DB 성능최적화 전략
PDF
HBase 훑어보기
PPTX
Apache solr소개 20120629
PDF
(130119) #fitalk sql server forensics
PDF
일래스틱 서치 ch7. 일래스틱 서치 클러스터 세부사항
PPTX
An introduction to hadoop
PDF
Mongo db 활용 가이드 ch7
PPT
Device driver
PDF
Ch1 일래스틱서치 클러스터 시작
PDF
(130525) #fitalk ntfs log tracker (korean)
(150124) #fitalk advanced $usn jrnl forensics (korean)
리눅스 간단 강의 2강
리눅스 간단 강의 4강
하둡 타입과 포맷
Soma search
Hadoop발표자료
엘라스틱서치, 로그스태시, 키바나
hadoop ch1
Mongo DB 성능최적화 전략
HBase 훑어보기
Apache solr소개 20120629
(130119) #fitalk sql server forensics
일래스틱 서치 ch7. 일래스틱 서치 클러스터 세부사항
An introduction to hadoop
Mongo db 활용 가이드 ch7
Device driver
Ch1 일래스틱서치 클러스터 시작
(130525) #fitalk ntfs log tracker (korean)
Ad

Viewers also liked (11)

PPTX
Java, android 스터티2
PPTX
Java, android 스터티1
PPTX
Java, android 스터티9
PDF
16.02.27 해킹캠프 오픈 소스 최우석
PPTX
Java, android 스터티10
PPTX
디지털 인문학 데이터베이스 개론
PPTX
파이썬 sqlite 이해하기
PDF
파이썬 튜토리얼 (Python tutorial)
PPTX
KGC 2016: HTTPS 로 모바일 게임 서버 구축한다는 것 - Korea Games Conference
PPTX
Python 이해하기 20160815
PDF
[야생의 땅: 듀랑고] 서버 아키텍처 Vol. 2 (자막)
Java, android 스터티2
Java, android 스터티1
Java, android 스터티9
16.02.27 해킹캠프 오픈 소스 최우석
Java, android 스터티10
디지털 인문학 데이터베이스 개론
파이썬 sqlite 이해하기
파이썬 튜토리얼 (Python tutorial)
KGC 2016: HTTPS 로 모바일 게임 서버 구축한다는 것 - Korea Games Conference
Python 이해하기 20160815
[야생의 땅: 듀랑고] 서버 아키텍처 Vol. 2 (자막)
Ad

Similar to sqlserver7.0 데이타베이스 (20)

PPTX
181215 MS SQL로 알아보는 데이터베이스
PPT
6.테이블만들기
PDF
#1.SQL초보에서 Schema Objects까지(SQL학원/오라클학원/IT실무교육학원/재직자/실업자교육학원추천)
PPTX
오라클 DB 아키텍처와 튜닝
PDF
제8장 테이블 생성 수정 제거하기
PDF
2016년 인문정보학 Sql세미나 1/3
DOC
제1회 Tech Net Sql Server 2005 T Sql Enhancements
DOC
Sql Server 2005 개요
PDF
Let's Play with Data Safely
PDF
데이터야 안전하게 놀아보자.V.1
PDF
Fundamentals of Oracle SQL
PDF
Database Entity, 정규화에 대해 알아보자.pdf
PDF
[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4
PPT
7.데이터수정
PDF
대량의 DML 작업에 대한 성능개선방안_Wh oracle
PPTX
DBMS 아키텍처
PPTX
03주차 ddl- table을 만들자
PPTX
02주차 ddl- db를 만들자
PPTX
03주차 ddl- table을 만들자
DOCX
MySQL_SQL_Tunning_v0.1.3.docx
181215 MS SQL로 알아보는 데이터베이스
6.테이블만들기
#1.SQL초보에서 Schema Objects까지(SQL학원/오라클학원/IT실무교육학원/재직자/실업자교육학원추천)
오라클 DB 아키텍처와 튜닝
제8장 테이블 생성 수정 제거하기
2016년 인문정보학 Sql세미나 1/3
제1회 Tech Net Sql Server 2005 T Sql Enhancements
Sql Server 2005 개요
Let's Play with Data Safely
데이터야 안전하게 놀아보자.V.1
Fundamentals of Oracle SQL
Database Entity, 정규화에 대해 알아보자.pdf
[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4
7.데이터수정
대량의 DML 작업에 대한 성능개선방안_Wh oracle
DBMS 아키텍처
03주차 ddl- table을 만들자
02주차 ddl- db를 만들자
03주차 ddl- table을 만들자
MySQL_SQL_Tunning_v0.1.3.docx

sqlserver7.0 데이타베이스

  • 1. 6.Creating Database 데이터 저장 방식 데이터베이스 생성하기 데이터베이스 조작하기 파일그룹 생성 데이터 타입 생성 테이블 생성 스크립트 이용 도서관 데이터베이스 Practice
  • 2. 데이터 저장 방식 Extent (8 contiguous 8-KB pages) Page (8 KB) Tables,Indexes Data Database Data (file) .mdf or .ndf Log (file) .ldf Max row size = 8060 bytes
  • 3. 보충설명 - 모든 데이터베이스는 주 데이터 파일 (.mdf) 를 가지고 하나 또는 그 이상의 로그파일 (.ldf) 을 가진다 . 데이터베이스는 두번 째 데이터베이스 파일 (ndf) 을 가질 수 있다 . - 데이터베이스를 만들면 model 데이터베이스의 시스템 테이블 이 데이터베이스로 복사된다 . 따라서 데이터베이스는 최소한 model 데이터베이스보다 크거나 같게 된다 . -Row cannot span pages. 따라서 하나의 행에 넣을 수 있는 데이 터의 최대 크기는 8060 바이트이다 .( 오버헤드를 제외한 수치 ) - 테이블과 인텍스는 extent 에 저장되는대 extent 는 8 개의 연속 적인 페이지 따라서 64KB 이다 .
  • 4. 데이터베이스 생성하기 데이터베이스 정의 데이터베이스 이름 데이터베이스 크기 데이터베이스가 저장될 파일 CREATE DATABASE sample ON PRIMARY ( NAME=sample_data, FILENAME='c:\mssql7\data\sample.mdf', SIZE=10MB, MAXSIZE=15MB, FILEGROWTH=20%) LOG ON ( NAME=sample_log, FILENAME='c:\mssql7\data\sample.ldf', SIZE=3MB, MAXSIZE=5MB, FILEGROWTH=1MB)
  • 5. 데이터베이스 옵션 선택 데이터베이스 옵션 선택 자주 사용되는 옵션 dbo use only read only trunc. log on chkpt. autoshrink 데이터베이스 옵션 보기 sp_dboption, sp_helpdb, sp_spaceused
  • 6. 자주 사용되는 옵션 dbo use only - 데이터베이스의 사용을 데이터베이스 소유주로 제한한다 . Read only - 데이터베이스를 읽기전용으로 정의한다 . Select into/bulkcopy - 데이터베이스로 하여금 로그를 하지 않는 작업을 수행하도록 한다 . Trunc.log on chkpt - 체크포인트 프로세서 후의 로그를 지운다 . Autoshink - 데이터베이스 크기가 자동적으로 줄어들것인지를 결정한다 . Single user - 데이터베이스에 대한 접근을 한번에 한사람으로 제한한다 .
  • 7. 데이터베이스 조작하기 데이터와 로그 파일의 크기 증가 조절하기 트랜잭션 로그 확대 데이터베이스나 파일 줄이기 데이터베이스 제거
  • 8. 데이터와 로그 파일의 크기 증가 조절하기 ALTER DATABASE sample MODIFY FILE ( NAME = 'sample_log', SIZE = 10MB) GO ALTER DATABASE sample ADD FILE (NAME = sample_data2 , FILENAME='c:\mssql7\data\sample2.ndf', SIZE=10MB , MAXSIZE=20MB) GO 7 MB 3 MB
  • 9. 보충설명 - ALTER DATABASE 문을 사용하기 위해서는 master database 를 사용하고 있어야 한다 . - 데이터베이스의 크기를 조절하는 방법 1. 데이터베이스와 로그파일이 자동으로 증가하도록 한다 . 2. 현재 존재하는 데이터베이스와 로그파일의 현재크기와 최대 크기를 수동으로 증가 시킨다 . 3. 수동으로 두 번째 데이터베이스와 로그파일을 추가한다 .
  • 10. Transaction Log 가 작동하는 원리 Data modification is sent by application 1 Disk Modification is recorded in transaction log on disk 3 Data pages are located in, or read into, buffer cache and modified 2 Buffer Cache Disk Checkpoint writes committed transactions to database 4
  • 11. 트랜잭션 로그 확대 로그 감시 필요 시 로그 크기 확대 과부하 로그 생성 감시 다량의 데이터를 인덱스 테이블에 로딩 시 큰 트랜잭션 이미지나 텍스트 처리 수행 시
  • 12. 데이터베이스나 파일 줄이기 전체 데이터베이스 줄이기 데이터베이스내의 데이터 파일 줄이기 데이터베이스를 자동적으로 줄이기 DBCC SHRINKDATABASE (sample, 25) DBCC SHRINKFILE (sample_data, 10)
  • 13. 데이터베이스 제거 제거 방법 SQL Server Enterprise Manager DROP 문장 데이터베이스 제거 시 제한 사항 복구 시 (Restored) 사용자 접근 시 (connecting to it) 복제에서 출판시 (Publishing) DROP DATABASE northwind, pubs
  • 14. Leveraging the Windows NT Server Fault Tolerance Using Disk Striping (RAID Level 0) Using Disk Mirroring (RAID Level 1) Using Disk Striping with Parity (RAID Level 5) Using RAID with SQL Server
  • 15. 파일그룹 생성 northwind Database Northwnd.mdf C:\ Ordhist1.ndf Ordhist2.ndf D:\ Northwnd.ldf C:\ Default Filegroup OrderHistoryGroup sys... sys... sysusers sysobjects ... orders customers products ordhistyear2 ordhistyear1
  • 16. 보충설명 -1 - Filegroups are named collections of files -With filegroups. You can locate specific objects on a specific file Types of filegroups -The default filegroup : contains the primary data file and any other files that are not part of another filegroup. All system tables and all tables and indexes for which a filegroup was not specified upon creation are placed in the default filegroup -User-defined filegroup: which are any filegroups that are specified by using the FILEGROUP keyword in an ALTER DATABASE
  • 17. 보충설명 -2 예제 ) The following example creates a user-defined filegroup in thenorthwind database and adds a secondary data file to the user-defined filegroup ALTER DATABASE northwind ADD FILEGROUP orderhistorygroup GO ALTER DATABASE northwind ADD FILE ( NAME = ‘ordhistyear1’, FILENAME = ‘c:\mssql7\data\ordhist1.ndf’, SIZE - 5 MB), TO FILEGROUP orderhistorygroup GO
  • 18. 데이터 타입 생성 시스템 지원 데이터 타입 사용자 정의 데이터 타입의 생성과 제거
  • 19. 시스템 지원 데이터 타입 시스템 지원 데이터 타입 분류 이진 (Binary) - binary[ ], varbinary[ ] 문자형 (Character) - char[ ], varchar[ ] 유니코드 문자 (Unicode character)-nchar[ ], nvarchar[ ] 날짜와 시간 (Date and time) - Datetime, samlldatetime Exact 와 Approximate Numeric Data Exact Numeric Data - decimal[(p[,s])], numeric[p[,s]] Approximate - float[(n)], real
  • 20. 추가적인 시스템 제공 데이터 타입 Global identifier uniqueidentifier Integer int Monetary money, smallmoney Special bit, cursor, sysname, timestamp Text and Image text, image Unicode text ntext
  • 21. 사용자 정의 데이터 타입의 생성과 제거 생성 제거 사용자 정의 데이터 타입 생성 지침 EXEC sp_addtype isbn, 'smallint’, 'NOT NULL' EXEC sp_addtype zipcode, 'char(10)' EXEC sp_addtype longstring, 'varchar(63)' EXEC sp_droptype isbn
  • 22. 사용자 정의 데이터 타입 생성 지침 - 만약 칼럼의 길이가 변한다면 변하는 데이터 타입을 사용하라 . 예를 들면 , 이름의 리스트를 만들어야 한다면 , 고정된 char 보다 변할 수 있는 varchar 타입을 사용한다 . - 숫자 데이터 타입에 대해서는 요구되는 크기와 정확도를 고려 한다 . 일반적으로는 decimal 을 사용한다 . - 저장해야 되는 데이터가 8000 바이트보다 크다면 , text 나 image 테이터 타입을 사용하라 .(2GB 까지 저장가능 ).
  • 23. 테이블 생성 테이블 생성과 제거 열의 추가와 제거(SQL Server 7.0의 추가기능) 열 값의 생성
  • 24. 테이블 생성과 제거 Column name Data type NULL or NOT NULL CREATE TABLE member ( member_no lastname firstname middleinitial photograph ) member_no shortstring shortstring letter image NOT NULL, NOT NULL, NOT NULL, NULL, NULL
  • 25. 테이블의 생성 - 하나의 데이터베이스에 20 억 개의 테이블을 만들 수 있다 . - 테이블 당 1024 개의 칼럼을 가질 수 있다 . -NOT NULL 이 SQL Server 의 디폴트이다 . 테이블의 제거 - 테이블을 제거하기 전에 테이블과 다른 객체들과의 의존관계를 제거해야 한다 . 의존관계를 알아 볼려면 sp_depends 시스템 프로 시져를 사용한다 . Syntax DROP TABLE table_name [,…n]
  • 26. 열의 추가와 제거 ALTER TABLE sales ADD customer_name char(30) null ALTER TABLE sales DROP COLUMN sales_date 제거 Commission Sales_amount Sales_date Customer ID Customer_name
  • 27. 열 값의 생성 IDENTITY 속성 이용 Seed 값 설정 increment value 설정 가장 최근의 값 이용 : @@identity NEWID 함수와 식별자 데이터 타입의 이용 글로벌한 유일 값 DEFAULT 제약 이용
  • 28. IDENTITY 속성 이용하기 문법 CREATE TABLE table (column_name data_type [IDENTITY [seed [ , increment] NOT NULL) - 오직 하나의 칼럼만이 허용된다 . - 갱신될 수 없다 . - NULL 값을 허용하지 않는다 . - integer(int, smallint, tinyint), numeric, decimal 형과 사용되어야 한다 . -IDENT_SEED: seed, 시작값을 알려 준다 . -IDENT_INCR: 증가값을 알려 준다 .
  • 29. 예제 ) In this example, the customer table customer ID column is created with a uniqueidentifier data type, with a default value generated by the NEWID function. A unique value for the cust_id column will be generated for each new and existing row CREATE TABLE customer (cust_id uniqueidentifier NOT NULL DEFAULT NEWID(), Cust_name char(30) NOT NULL)
  • 30. Transact-SQL 스크립트를 이용한 스키마 생성 백업용 스크립트 이용 개발용 스크립트를 생성하거나 업데이트 테스트용 혹은 개발용 환경의 생성 새로운 직원을 훈련 생성할 수 있는 것 전체 데이터베이스 테이블 스키마 테이블과 인덱스 스키마 스크립트 이용
  • 31. 권장 사항 Place Database and Transaction Log on Separate Physical Disks Disable Write Caching on Disks Specify Maximum Size When You Use Automatic File Growth Back Up master Database After You Create or Modify a Database Generate Scripts to Re-create Database and Database Objects
  • 32. 데이터 베이스 예제 - 도서관 도서관 데이터베이스 생성
  • 33. 스키마 isbn copy_no title_no on_loan copy isbn title_no translation cover loanable item title_no title author synopsis title member_no street city state zip phone_no eaxpr_date adult isbn member_no log_date remarks reservation member_no lastname firstname middleinitial photograph member member_no adult_member_no birth_date juvenile isbn copy_no title_no member_no out_date due_date loan isbn copy_no out_date title_no member_no due_date in_date fine_assessed fine_paid fine_waived remarks loanhist
  • 34. Member Information juvenile member_no adult_member_no birth_date PK, FK FK, NN NN 3 4 5 2 1 1 Jun 01 1980 Mar 01 1978 Nov 05 1982 adult member_no street city state zip PK,FK NN NN NN NN 1 2 6 Elm St Bowery Ave Bowery Ave Seattle Seattle Kent WA WA WA 98022 98022 98206 phone_no NULL (206)555-1212 NULL expr_date NN Jun 06 1992 Aug 07 1992 Mar 03 1993 member member_no lastname firstname middleinitial photograph PK NN NN 1 2 3 4 5 6 Anderson Barr Barr Anderson Anderson Henson Andrew Andrew Bill Bill Sally Jack A R NULL B A NULL ~~~ ~~~ ~~~ ~~~ ~~~
  • 35. Item Information title_no copy_no on_loan isbn 1 1 2 3 4 4 Y Y N Y Y Y 1 2 1 1 1 2 1 1 2 3 4 4 copy FK, NN NN PK, FK PK PK FK, NN isbn title_no translation cover loanable 1 2 3 4 5 1 2 3 4 2 English French French NULL English softback NULL hardback hardback softback Y N Y NULL Y item PK NN title title_no title author NN synopsis 1 2 3 4 Gone With the Wind Color Purple Hotel Winnie the Pooh Mitchell Walker Hailey Milne ~~~ ~~~ ~~~
  • 36. Loan Information reservation isbn member_no log_date PK,FK PK, FK 1 1 4 2 3 3 3/7/1992 NULL 3/17/1992 remarks ~~~ NULL ~~~ loan isbn copy_no title_no member_no out_date PK,FK1 PK, FK1 FK,NN FK, NN PK, NN 1 4 4 3 1 1 1 2 1 2 1 4 4 3 1 1 1 2 3 1 03/18/92 03/15/92 03/17/92 03/18/92 03/15/92 due_date NN 03/29/92 03/29/92 04/01/92 04/02/92 03/29/92 loanhist isbn copy_no out_date PK,FK1 PK, FK1 NN 1 2 2 1 1 1 1 1 2 1 10/13/91 07/07/91 10/13/91 11/06/91 10/30/91 title_no FK,NN 1 2 2 1 1 member_no FK, NN 4 2 4 3 1 due_date 10/27/91 07/21/91 10/27/91 11/20/91 11/13/91 in_date 10/26/91 NULL 10/28/91 11/14/91 11/15/91 fine_assessed 0.00 0.10 0.00 0.20 0.00 fine_paid 0.00 0.00 0.00 0.20 0.00 fine_waived 0.00 0.10 0.00 0.00 0.00 remarks ~~~ ~~~ ~~~ ~~~
  • 37. 데이터베이스 만들기 (1) DB 의 이름을 적는다 .
  • 38. 데이터베이스 만들기 (2) 트랜잭션로그를 적는다 .