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.
5.
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:ssql7ataample2.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
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:ssql7atardhist1.ndf’, SIZE - 5 MB), TO FILEGROUP orderhistorygroup GO
18.
19.
20. 추가적인 시스템 제공 데이터 타입 Global identifier uniqueidentifier Integer int Monetary money, smallmoney Special bit, cursor, sysname, timestamp Text and Image text, image Unicode text ntext
21.
22. 사용자 정의 데이터 타입 생성 지침 - 만약 칼럼의 길이가 변한다면 변하는 데이터 타입을 사용하라 . 예를 들면 , 이름의 리스트를 만들어야 한다면 , 고정된 char 보다 변할 수 있는 varchar 타입을 사용한다 . - 숫자 데이터 타입에 대해서는 요구되는 크기와 정확도를 고려 한다 . 일반적으로는 decimal 을 사용한다 . - 저장해야 되는 데이터가 8000 바이트보다 크다면 , text 나 image 테이터 타입을 사용하라 .(2GB 까지 저장가능 ).
23.
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.
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.
31.
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 ~~~ ~~~ ~~~