- 在线时间
- 0 小时
- 最后登录
- 2007-9-23
- 注册时间
- 2004-9-10
- 听众数
- 3
- 收听数
- 0
- 能力
- 0 分
- 体力
- 9975 点
- 威望
- 7 点
- 阅读权限
- 150
- 积分
- 4048
- 相册
- 0
- 日志
- 0
- 记录
- 0
- 帖子
- 1893
- 主题
- 823
- 精华
- 2
- 分享
- 0
- 好友
- 0

我的地盘我做主
该用户从未签到
|
< >Create Table
9 e! s. \' ]7 f( _; x- h7 o用途: 8 k# u' B; V9 i" Y
</P>< > 建立新的资料表。</P>< >语法:
1 l$ Q- b8 s. h F) u. |# Z7 I </P>< >CREATE TABLE table_name
4 f- w6 N# `6 n& g(
* ]" O" R3 B% t+ E: F; z8 Vcolumn_name1 data_type,
7 h3 }9 @$ p7 L( x- S$ b) acolumn_name2 data_type, / [) f& I. C8 h: {" A; _1 [
....... T, R; T2 n) N" O$ D0 z
)
* ~4 O4 Z. W/ O) V' @
1 t0 I& y; s! S: l例:
2 a/ w$ G) b! Z </P>< >创建一张叫" erson"的表,该表有4个字段"LastName", "FirstName", "Address", "Age": 3 b& q) Q# w9 U. ~# ]. k/ `% Z
</P>< >CREATE TABLE Person 7 s0 [0 P$ }: e: @: K
(
, k, N; K& Y6 mLastName varchar,
- S. J8 R/ T: r+ sFirstName varchar, , D5 [- k% x0 c* A
Address varchar,
5 o# C, I. h, o. xAge int , H. W+ C, n+ K, L/ J! g5 ~
) ' X% U' \5 ?" i2 i, W
</P>< >如果想指定字段的最大存储长度,你可以这样:</P>< >CREATE TABLE Person / j; [- j5 w3 I9 ^+ Y6 ^
(
/ g! ~) |, d) z/ U8 h3 RLastName varchar(30),
" G# M4 r( r/ I& F6 o5 {" }FirstName varchar(30),
% o; W! l8 }& v- d- pAddress varchar(120),
6 `! ^8 x: f$ h ]+ U1 sAge int(3) 5 z( X) k) g+ m6 b2 F7 r- u
) 7 h! W; a' G7 x, e0 I5 ]! H
</P>< >下表中列出了在SQL的一些数据类型:</P>< >Data Type 6 }# X2 S" t$ v: S2 o. W- c
5 y5 j" G- E5 {
Description ' ^ m! L9 q' [$ @
4 a4 J6 j% B* I$ g4 |, n' H' \- ^% @; I
0 \, E/ y, U) _+ J
integer(size), m* H; s, E* F s
int(size). t+ Z6 j* n7 v# O1 n, Y
smallint(size)
7 H# H7 y& w$ }/ stinyint(size) . W6 G, i1 x- o! k- ]
2 s' n1 e' f* O
Hold integers only. The maximum number of digits are specified in parenthesis. 2 k+ m) F2 Y c4 q [* _
( D/ j; b% G. E. n+ O+ `
* H) m" ]; @: r; [- M7 q9 bdecimal(size,d)- z/ B9 `- Y& [3 _! c
numeric(size,d)
( w" o. I& b- W+ X# u: C) \ 1 d7 H! _/ p* h. C6 [# \/ l
Hold numbers with fractions. The maximum number of digits are specified in "size". The maximum number of digits to the right of the decimal is specified in "d".
; X; i' u/ J; Z' i- c
- }# ^7 Z, k' e+ D/ C1 \ # s, Z1 o8 K! ]& g) }& h
char(size)
) D2 H7 @) U* q; f6 Y" f( o1 {( R
4 }& j+ X' i/ u1 j6 t Holds a fixed length string (can contain letters, numbers, and special characters). The fixed size is specified in parenthesis. 6 W! q) S5 o* t
5 S- o8 J+ r% \" ~
6 w5 i: f( n! t0 hvarchar(size) : H. M3 O: b. e* D8 Z1 H) [/ U& h
0 S5 ~8 e4 V" _, f
Holds a variable length string (can contain letters, numbers, and special characters). The maximum size is specified in parenthesis.
4 {2 e9 b, ]* D5 c# |
8 K; r3 C9 z" M5 o 0 a* j8 X$ L. Q/ Z/ s
date(yyyymmdd) 4 D2 n3 B. t3 V
4 D: ?+ C7 R, V. a" T2 J5 w Holds a date
; g( U+ b% [0 [1 Z1 e- F
# B% D2 k, M0 t1 K& ]
$ W8 y3 y9 B& U$ e, z, \& b
3 f9 S0 ~/ g" @" j8 [7 }- j </P>< > 7 b4 p i- B7 {9 V( ~! N1 d
</P>< >Alter Table
6 u; y {7 r+ L) \# T) x1 f$ w用途: " ~5 c# p. f' {4 V
</P>< > 在已经存在的表中增加后者移除字段</P>< >语法: 9 \4 l8 m. K' C$ d% L" W+ c
</P>< >ALTER TABLE table_name
9 q' j' v* V- e8 X0 s3 I6 rADD column_name datatype </P> |
|