MySQL修改表结构
目录
MySQL修改表结构
在本教程中,您将了解并使用MySQL ALTER TABLE
语句来更改现有表结构(如添加或删除列,更改列属性等)。
MySQL ALTER TABLE语句简介
可以使用ALTER TABLE
语句来更改现有表的结构。 ALTER TABLE
语句可用来添加列,删除列,更改列的数据类型,添加主键,重命名表等等。 以下说明了ALTER TABLE
语句语法:
ALTER TABLE table_name action1[,action2,…]
要更改现有表的结构:
- 首先,在
ALTER TABLE
子句之后指定要更改的表名称。 - 其次,列出一组要应用于该表的操作。操作可以是添加新列,添加主键,重命名表等任何操作。
ALTER TABLE
语句允许在单个ALTER TABLE
语句中应用多个操作,每个操作由逗号(,
)分隔。
让我们创建一个用于练习ALTER TABLE
语句的新表。
我们将在示例数据库(yiibaidb)中创建一个名为tasks
的新表。 以下是创建tasks
表的脚本。
DROP TABLE IF EXISTS tasks;
CREATE TABLE tasks (
task_id INT NOT NULL,
subject VARCHAR(45) NULL,
start_date DATE NULL,
end_date DATE NULL,
description VARCHAR(200) NULL,
PRIMARY KEY (task_id),
UNIQUE INDEX task_id_unique (task_id ASC)
);
使用MySQL ALTER TABLE语句更改列
使用MySQL ALTER TABLE语句来设置列的自动递增属性
假设您希望在任务表中插入新行时,task_id
列的值会自动增加1
。那么可以使用ALTER TABLE
语句将task_id
列的属性设置为AUTO_INCREMENT
,如下所示:
ALTER TABLE tasks
CHANGE COLUMN task_id task_id INT(11) NOT NULL AUTO_INCREMENT;
可以通过在tasks
表中插入一些行数据来验证更改。
INSERT INTO tasks(subject,
start_date,
end_date,
description)
VALUES('Learn MySQL ALTER TABLE',
Now(),
Now(),
'Practicing MySQL ALTER TABLE statement');
INSERT INTO tasks(subject,
start_date,
end_date,
description)
VALUES('Learn MySQL CREATE TABLE',
Now(),
Now(),
'Practicing MySQL CREATE TABLE statement');
您可以查询数据以查看每次插入新行时task_id
列的值是否增加1
:
SELECT
task_id, description
FROM
tasks;
使用MySQL ALTER TABLE语句将新的列添加到表中
由于新的业务需求,需要添加一个名为complete
的新列,以便在任务表中存储每个任务的完成百分比。 在这种情况下,您可以使用ALTER TABLE
将新列添加到tasks
表中,如下所示:
ALTER TABLE tasks
ADD COLUMN complete DECIMAL(2,1) NULL
AFTER description;
使用MySQL ALTER TABLE从表中删除列
假设您不想将任务的描述存储在tasks
表中了,并且必须将其删除。 以下语句允许您删除tasks
表的description
列:
ALTER TABLE tasks
DROP COLUMN description;
使用MySQL ALTER TABLE语句重命名表
可以使用ALTER TABLE
语句重命名表。请注意,在重命名表之前,应该认真考虑以了解更改是否影响数据库和应用程序层,不要因为重命名表之后,应用程序因未找到数据库表而出错。
以下语句将tasks
表重命名为work_items
表:
ALTER TABLE tasks
RENAME TO work_items;
在本教程中,您学习了如何使用MySQL ALTER TABLE
语句来更改现有的表结构并重命名表。
移动端:请扫描本页面底部(右侧)二维码并关注微信公众号,回复:”教程” 选择相关教程阅读
augmentin 625mg cheap order clomid order serophene sale
lexapro 20mg sale order prozac purchase naltrexone online
lasix 100mg uk buy furosemide generic diuretic buy albuterol pills
atomoxetine usa buy quetiapine online cheap order sertraline 100mg pill
urso 300mg drug buy cetirizine tablets cheap zyrtec 10mg
buy azithromycin no prescription order gabapentin 600mg online buy gabapentin 100mg pill
good acid reducer instant supplements that help acid reflux pills that stop farting
prednisone generic accutane usa amoxil over the counter
online birth control consultation who should not take cialis pills for larger ejaculation
order promethazine 25mg online cheap erectile dysfunction drug stromectol for human
drugs for peptic ulcer types of vasodilator drugs otc pain relief for uti
purchase cymbalta order cymbalta 20mg sale order modafinil without prescription
best supplements for fungus best antiviral drug for herpes list of low sodium snacks
purchase cyproheptadine cost ketoconazole nizoral sale
ordering valtrex overnight delivery diabetic pill medicine best medicine for diabetes reduction
cost medroxyprogesterone cost biltricide buy microzide
medicine to stop smoking cigarettes nicotine medication for quitting tobacco strongest pain relief medication
letrozole 2.5 mg oral femara 2.5 mg cost how to get abilify without a prescription
diphenhydramine hcl nighttime sleep aid xeljanz fda approval for alopecia wares mexico pharmacy diet pills
buy uroxatral 10mg generic alfuzosin 10mg pills best painkiller for stomach pain
order minocin generic buy requip 1mg generic requip 1mg canada
acne ointment by prescription only adult acne medication oxcarbazepine 600mg without prescription
purchase catapres for sale order antivert 25mg without prescription buy tiotropium bromide pill
rocaltrol 0.25mg price tricor 200mg pills tricor uk
trimox brand clarithromycin oral clarithromycin 500mg sale
buy essay online uk casino online real money roulette online
academicwriters buy suprax 100mg without prescription buy suprax 200mg
aspirin 75mg uk casino blackjack online slot games
terbinafine 250mg usa best online casino games pala casino online
buy trazodone online order sildenafil 100mg pill buy cheap generic clindac a
buy generic cefuroxime for sale cefuroxime price robaxin 500mg uk
buy tadacip tablets diclofenac 100mg generic cheap indocin 50mg
nolvadex 10mg oral buy betahistine 16mg sale order generic rhinocort
purchase tretinoin online brand retin cream purchase avana
lamictal order online brand lamotrigine 200mg cheap mebendazole
generic metronidazole keflex sale order cephalexin 250mg online
aurogra oral estradiol 2mg tablet order estradiol 1mg generic
buy forcan without a prescription buy diflucan 100mg generic buy baycip paypal
teach me how to write an essay write research paper buy an essay cheap
brand spironolactone proscar online buy propecia generic
order motilium generic motilium 10mg for sale sumycin pill
order flomax 0.4mg generic cost zofran 8mg cheap simvastatin 10mg
buy buspar 10mg pills order amiodarone 200mg without prescription order cordarone pills
purchase ranitidine without prescription order zantac 150mg generic celebrex 200mg us
buy cheap generic zyloprim rosuvastatin 20mg usa buy rosuvastatin 20mg generic
generic sumatriptan 25mg buy cheap levaquin buy generic dutasteride
esomeprazole without prescription mirtazapine generic topamax 200mg for sale
astelin sprayers buy astelin 10ml online purchase avalide for sale
famotidine 40mg drug tacrolimus 5mg pill prograf 5mg without prescription
xenical tablet purchase orlistat sale diltiazem 180mg usa
coumadin price cost paroxetine 20mg metoclopramide 20mg drug
pamelor 25 mg canada order panadol 500mg online cheap acetaminophen 500mg generic
buy inderal 20mg pills plavix buy online buy plavix 150mg sale
Захотелось азарта, и я решил найти казино на деньги через Яндекс. На первом месте был сайт caso-slots.com, где представлены различные казино с игровыми автоматами, бонусы на депозит и статьи с советами по игре. Все, что нужно для успешной игры!
fosamax 70mg us where can i buy colchicine nitrofurantoin 100mg without prescription
buy amaryl 4mg sale misoprostol pill oral etoricoxib 60mg
buy cheap generic lioresal cost endep toradol over the counter
loratadine us order generic loratadine 10mg order dapoxetine pills
baclofen oral buy toradol without a prescription buy ketorolac pill
cheap phenytoin buy generic cyclobenzaprine for sale buy ditropan 2.5mg generic
buy generic perindopril 8mg fexofenadine 180mg ca allegra 120mg ca
buy vardenafil no prescription how to buy digoxin buy cheap tizanidine
methylprednisolone 4mg without a doctor prescription fda methylprednisolone triamcinolone buy online
buy clomid without prescription clomiphene over the counter buy imuran 50mg online
ocean casino online levoxyl pills levoxyl online order
Недавно мне понадобилось 4 000 рублей на неотложные нужды. По совету друга, я посетил yelbox.ru. Там я нашел много полезных статей о том, как правильно взять займы на карту онлайн и список проверенных МФО. И узнал, что некоторые из них предоставляют займы без процентов!
order symmetrel 100 mg generic symmetrel over the counter purchase aczone
free slot play recommended you read stromectol lotion
roulette free buy acticlate for sale purchase ventolin inhalator generic
order pantoprazole generic buy generic pyridium for sale order phenazopyridine without prescription
poker online sites roulette casino furosemide online buy
buy azithromycin 500mg omnacortil uk gabapentin order
generic atorvastatin 80mg purchase amlodipine brand amlodipine 10mg
accutane cheap order generic azithromycin 250mg azithromycin 500mg pill
order cefdinir pills order glucophage 1000mg generic cheap prevacid 15mg
order provigil 100mg generic order deltasone 20mg sale buy prednisone 5mg without prescription
cenforce for sale online order naproxen 250mg generic chloroquine 250mg uk
buy telmisartan generic buy micardis 80mg online cheap movfor over the counter
order cialis 10mg without prescription buy cialis 20mg pills viagra 100mg tablet
buy prilosec 20mg montelukast online order metoprolol price
premarin 600 mg without prescription cheap sildenafil 50mg viagra 100mg pills
order generic betahistine 16 mg order haldol sale order probenecid 500 mg sale
buy zovirax sale exelon 6mg for sale rivastigmine 3mg uk
purchase enalapril for sale purchase lactulose bottless duphalac where to buy
order ferrous 100 mg pills purchase sotalol online cheap buy betapace no prescription
mestinon tablet order piroxicam 20 mg without prescription cheap maxalt
pill prasugrel 10 mg chlorpromazine 50 mg over the counter how to get detrol without a prescription
order generic monograph cilostazol sale buy pletal generic
fludrocortisone 100 mcg canada florinef where to buy loperamide 2 mg without prescription
order dydrogesterone 10 mg jardiance 25mg over the counter jardiance 10mg sale
meloset 3 mg for sale buy meloset 3mg sale order danocrine 100 mg generic
dipyridamole pill order dipyridamole for sale pravastatin order
aspirin 75mg tablet order hydroquinone online cheap zovirax online
order acarbose 50mg order fulvicin 250mg without prescription fulvicin 250 mg cost
buy mintop generic mintop solution can you buy ed pills online
buy ketotifen 1mg for sale geodon 40mg brand buy imipramine 25mg generic
us cialis order sildenafil for sale generic sildenafil 50mg
order fenofibrate 200mg generic tricor cost tricor 200mg canada