5
5 Normalization () Customer IDCustomerNameCustomer Address
9118/18 .- .18
92100/6 . 2 .
94 () G The Mall - 275 1 . .
95 1770 . .
() ( ) SQL Server 2,000 1 Primary Key Foreign Keys , Data Integrity SQL Management Studio
SQL Server Management Studio Transact SQL 1. 2. Tables New Table
3. Table Design , ,
5.1 3 TblProducts 1. 2. Tables New Table.
3. Table Design , , (Field Name)(Date Type)(Description)
ProductIDInt
CategoryIDInt
ProductNameNchar(50)
UniPriceMoney()
VATFlagBit
ProductID
4. TbIProducts Table Design TbIProducts
Note Primary Key Primary Key Comstraints
5.2
TbICategories 1. 2. Tables New Table
3. Table Design , , (Field Name)(Date Type)(Description)
CategoryIDInt
CategoryNamenvarchar(50)
CategoryDescriptionNtext
CategoryPictureImage
CategoryID 4. TbICtegories Table Design TbICategories
CREATE TABLE
Transact SQL CREATE TABLE CREATE TABLE , Constraints CREATE TABLE CREATE TABLE [database.]ormer.]table_name
(,column_name datatype[not null]IDENTITY[(seed,increment) ][constraint][,column_name datatype [not null | null IDENTITY[(seed,increment)]]][constraint]..)[ON file group]
NULL
CREATE TABLE NULL NOT NULL NOT NULL
NULL NULL ASCll NULL
NULL (null) 2 NULL
NULL NULL NULL quote () (NULL) NULL
CREATE TABLE TblProducts ProductID, CategoryID, ProductName, UnitPrice, VATFlag, UnitinStock ProductID Primary Key
Tip
USE database_name
database_name ldentity
identity (Seed) (increment) identity
identity col1 =1 =1 1,2,3,4,5,.. identity Column Properties SQL Server Management Studio CREATE TABLE identity
BIGINT,INT, SMALLINT, TANYINT, DECIMAL NOT NULL Tip
identityCol identity
SELECT identity Col FROM TblProductsNote
sa sysadmin fixed server role () 128
SQL Server , , 1 1,024 Tip
sp_spaceused USE Orders
sp_spaceused TvlProducts
TblProducts Orders
TINYINT 0-255 1
SMALLINT -32,768 32,767 2
INT INTEGER, (2^31) (2^31) -1 -2,147,483,647 4
BIGINT (2^63) (2^63)-1 8
SQL Server 100000 Smallint 32,767 SQL Server
SQL Server 2
Approximate Numeric Data Types
Float Real
FLOAT[(n)] 1.7 E -308 1.7 E+308 8 n 15 n 1 53 n 1-24 7 4 25-53 15 8
REAL -3.4 E 3.4E+38 4 7 FLOAT (24)
Exact Numeric Data Types DECIMAL NUMERIC
DECIMAL[(p[,s])], NUMERIC[(p[,s])] DECIMAL NUMERIC p s -10^38+1 10^38-1 5 17 , P (precision) p 18 p 1 38 (1