—恢复内容开始—
一:介绍
约束条件与数据类型的宽度一样 ,都是可选参数
作用,用于保证数据的完整性和 一致性
主要分为:
primary key (pk) 标识该字段为该表的主键, 可以唯一的标识记录 foreign key (fk) 标识该字段为该表的外键 not null 标识该字段不能为空 unique key(uk) 标识该字段的值是唯一的 auto_increment 标识该字段的值自动增长(整数类型吗而且为主键) default 为该字段设置默认值 unsigned 无符号 zerofill 使用0填充
说明: 1:是否允许为空, 默认NULL,可设置NOT NULL ,字段不允许为空吗必须赋值, 2:字段是否有默认值, 默认值是NULL,如果插入记录时不给字段赋值,此字段就使用默认值null. sex enum('male','female') not null default 'male' age int unsigned NOT NULL default 20 必须为正值(无符号) 不允许为空 默认是20 3:是否是key 主键:primary key 外键:foreign key 索引(index,unique......)
二: not null 与default
是否可空:null表示空, 非字符串
not null 表示不可空
null-可空
default 默认
默认值 创建列时可以指定默认值,当插入数据时如果未主动设置,则自动添加默认值
三 unique 唯一约束
========================== 设置唯一约束 UNIQUE 方法一: create table department1( id int, name varchar(20) unique, comment varchar(100) ); mysql> insert into department1 values(1,'IT','技术'); Query OK, 1 row affected (0.00 sec) mysql> insert into department1 values(2,'IT','技术'); ERROR 1062 (23000): Duplicate entry 'IT' for key 'name' #在创建department1 表时,已经在name处设置了唯一,所以name 处得值就不可以是相同得, 每个都得 是唯一得。
四: primary key
从约束得角度看primary key 字段的值不为空且唯一, 那么我们直接使用 not null +unique 不就可以了吗,要它干什么?
primary key 又称主键 是innodb 的存储引擎组织数据的依据, innodb称之为索引组织表, 一张表中必须有且只有一个主键。
============单列做主键=============== #方法一:not null+unique create table department1( id int not null unique, #主键 name varchar(20) not null unique, comment varchar(100) ); mysql> desc department1; +---------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+--------------+------+-----+---------+-------+ | id | int(11) | NO | PRI | NULL | | | name | varchar(20) | NO | UNI | NULL | | | comment | varchar(100) | YES | | NULL | | +---------+--------------+------+-----+---------+-------+ rows in set (0.01 sec) #方法二:在某一个字段后用primary key create table department2( id int primary key, #主键 name varchar(20), comment varchar(100) ); mysql> desc department2; +---------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+--------------+------+-----+---------+-------+ | id | int(11) | NO | PRI | NULL | | | name | varchar(20) | YES | | NULL | | | comment | varchar(100) | YES | | NULL | | +---------+--------------+------+-----+---------+-------+ rows in set (0.00 sec) #方法三:在所有字段后单独定义primary key create table department3( id int, name varchar(20), comment varchar(100), constraint pk_name primary key(id); #创建主键并为其命名pk_name mysql> desc department3; +---------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+--------------+------+-----+---------+-------+ | id | int(11) | NO | PRI | NULL | | | name | varchar(20) | YES | | NULL | | | comment | varchar(100) | YES | | NULL | | +---------+--------------+------+-----+---------+-------+ rows in set (0.01 sec)
五:auto_increment 自增,
1、通常与primary key 连用, 而且通常是给id字段加,无需在于其赋值
2、auto_increment 只能给被定义成key (unique key, primary key,)的字段加。
create table t20( id int primary key auto_increment, name char(16) )engine=innodb; # 一般是加在id上
—恢复内容结束—
sildenafil for sale brand viagra australia generic viagra online
sinus infection cephalexin can you drink and take cephalexin does cephalexin treat impetigo
are keflex and cefazolin in the same family cephalexin for dogs uses cephalexin with food
keflex for otitis media can cephalexin treat sore throat what is cephalexin 500mg
can you take cephalexin with penicillin allergy canine cephalexin dose cephalexin what is it used for
amoxicillin uti dose azithromycin and amoxicillin together side effects amoxicillin for ear infection
can i take amoxicillin with tylenol zyrtec for amoxicillin rash does amoxicillin contain penicillin
augmentin 625 for children augmentin trockensaft 457 augmentin 500/125 mg comprimidos
augmentin pharmacology structural formula of augmentin augmentin duo antibiotic
amoxicillin 500mg dosage for adults how many days can you take acetaminophen with amoxicillin does amoxicillin make you dizzy
prednisone 060 prednisone uses for dogs how long can prednisone delay your period
prednisone dosage for allergic rhinitis prednisone 059 prednisone taper side effects
ciprofloxacin tablets usp 750 mg ciprofloxacin for sinus infection ciprofloxacin and doxycycline for uti
what is the difference between doxycycline hyclate and doxycycline monohydrate doxycycline hyclate and dairy can you take doxycycline while pregnant
doxycycline para que es doxycycline dog side effects does doxycycline make you sleepy
ciprofloxacin ophthalmic for ears can you eat cheese while taking ciprofloxacin how long after taking ibuprofen can i take ciprofloxacin
aquatic azithromycin 250 mg azithromycin brand azithromycin used for
cialis black online cialis uk no prescription cialis generic china
where can i buy generic viagra online order viagra from india where to buy female viagra uk
viagra from mexico to usa where can i buy viagra canada online pharmacy viagra paypal
vcialis tadalafil tablets prices tadalafil herbal substitute
purchase cialis cialis buy online cialis back pain
special sales on cialis tadalafil side effects cialis tadalafil 5mg once a day
cialis generic cipla how to get a prescription for cialis cialis las vegas
buy viagra canada online mexico pharmacy viagra buy viagra 150 mg
sildenafil 25 mg buy generic viagra sildenafil sildenafil from india
reflection essay example college essay best essay editing service
essay meaning no essay scholarship essay conclusion help
help writing a essay essay conclusion examples shark essay
application essay writing service how to write a essay help with writing essays
how to start an analysis essay essay on time management i need help writing a compare and contrast essay
essay help online write my essay for money tell me about yourself essay
essay writing service law self evaluation sample essay essay writer helper
rx pharmacy india river pharmacy baclofen advanced rx pharmacy
online pharmacy no prescription cialis best online pharmacy alprazolam advair pharmacy price
in house pharmacy propecia overseas pharmacies target pharmacy prednisolone
xanax pharmacy online review kamagra pharmacy online target pharmacy meloxicam
tadalafil usa pharmacy ventolin target pharmacy viagra certified pharmacy online
differin gel pharmacy telmisartan online pharmacy levofloxacin pharmacy
pharmacy degree online online pharmacy doxycycline zetia online pharmacy
indian pharmacy alprazolam online pharmacy buy viagra tesco pharmacy doxycycline
nabp pharmacy viagra levitra uk pharmacy sainsburys pharmacy viagra
tadalafil (cialis) price does green lumber still have tadalafil what happens if tadalafil doesn’t work
cialis tadalafil cost sunrise tadalafil tablets is tadalafil a nitrate
tadalafil 40 mg online goodrx tadalafil 5mg sildenafil and tadalafil together
how long does 5 mg tadalafil last tadalafil 5mg everyday does tadalafil cause weight gain
is tadalafil better than cialis tadalafil 20mg cost combining low dose tadalafil with sildenafil
sildenafil, tadalafil, and vardenafil tadalafil fatty meal tadalafil high blood pressure
can i take 60 mg of tadalafil cheapest tadalafil order tadalafil 20mg
mix tadalafil and sildenafil tadalafil cialis tadalafil better than sildenafil
does walgreens sell tadalafil tadalafil vidalista 80 mg tadalafil 80mg dosage
tadalafil tablet uses using tadalafil and sildenafil taken together tadalafil and sildenafil difference
tadalafil 5 mg tablet uses auro tadalafil tadalafil 10 mg coupon
tadalafil walgreens tadalafil 60 mg dosage tadalafil 20 mg vs cialis
tadalafil over the counter cvs tadalafil cialis 5mg tadalafil 20 mg for female
tadalafil 1a pharma 5mg oxytocin/tadalafil side effects canadian pharmacy tadalafil
low cost tadalafil online best research tadalafil 2017 chrisale tadalafil 20 mg para que sirve
where can i buy tadalafil tamsulosin and tadalafil is tadalafil better than cialis
best 5mg tadalafil tadalafil honey sildenafil and tadalafil together
alternatives to tadalafil does tadalafil increase libido is viagra better than tadalafil
tadalafil 20mg uk
tadalafil overnight delivery
online pharmacy oxycodone
cheap online pharmacy viagra
generic viagra 20 mg
female viagra pharmacy australia
cialis coupon free trial
where can i find viagra
cialis shipped from usa
tadalafil 20 mg online pharmacy
where can you buy real generic viagra
buy viagra over the counter nz
where to get free samples of cialis
tadalafil sublingual tablet 20mg
snafi tadalafil 20mg
brand cialis canada
metronidazole gyogyszer
sulfamethoxazole-tmp ds tablet bloody stool
cheap generic zithromax