1、創(chuàng)建數(shù)據(jù)庫
1.1 CREATE TABLE IF NOT EXIST 表名(
字段名 ?int not null
)
關(guān)鍵字:if not exists 如果不存在創(chuàng)建表
約束詞:
not null
* NOT NULL約束強(qiáng)制列不接受NULL值。
例: softis int not null
unique
* UNIQUE約束唯一標(biāo)識(shí)數(shù)據(jù)庫表中的每條記錄
例:softid unique
primary key
* PRIMARY KEY約束唯一標(biāo)識(shí)數(shù)據(jù)庫表中的每條記錄(可以是多個(gè)值)
例: create table if not exists CLT(
softid ,
cl ,
primary key(softid, cl)
)
check
* CHECK約束用于限制列中的值的范圍
例: create table if not exists CLT(
softidint check(softid > 10)
)
default
* DEFAULT約束用于向列中插入默認(rèn)值
例: itemid default 'CL'
2、數(shù)據(jù)類型
tinyint(size)0 ~ 225僅容納整數(shù),在括號(hào)內(nèi)規(guī)定數(shù)字內(nèi)最大位數(shù)
smallint(size)-2^15 ~ 2^31
integer(size)同int
int(size)-2^31 ~ 2^31
bigint(size)-2^64 ~ 2^64
decimal(size, d)容納帶有小數(shù)的數(shù)字
numeric(size, d)‘size’規(guī)定的最大數(shù)。'd'規(guī)定小數(shù)點(diǎn)右側(cè)的最大位數(shù)
char(size)容納固定長度的字符串(可容納字母、數(shù)字以及特殊字符)
在括號(hào)中規(guī)定字符串的長度
varchar(size)容納可變長度的字符串(可容納字母、數(shù)字以及特殊的字符)
在括號(hào)中規(guī)定字符串的最大長度
date(yyyymmdd)容納日期
3、基本操作
SELECT語句用于查詢
語法:
select [列名稱] from [表名稱] //指定列?
select * from [表名稱]