Home Database Mysql Tutorial sql alert 添加、修改、删除字段语法实例

sql alert 添加、修改、删除字段语法实例

Jun 07, 2016 pm 05:47 PM
alert sql Revise delete Field Add to

sql alert 添加、修改、删除字段语法实例
alter table 的语法如下:

alter table "table_name"
[改变方式]

[改变方式] 的详细写法会依我们想要达到的目标而有所不同。再以上列出的改变中,[改变方式] 如下:

加一个栏位: add "栏位 1" "栏位 1 资料种类"
删去一个栏位: drop "栏位 1"
改变栏位名称: change "原本栏位名" "新栏位名" "新栏位名资料种类"
改变栏位的资料种类: modify "栏位 1" "新资料种类"


主键

   alter table tabelname add new_field_id int(5) unsigned default 0 not null auto_increment ,add primary key (new_field_id);


//增加一个新列

   alter table t2 add d timestamp;
alter table infos add ex tinyint not null default '0';
//删除列

   alter table t2 drop column c;
//重命名列

   alter table t1 change a b integer;

//改变列的类型

   alter table t1 change b b bigint not null;
alter table infos change list list tinyint not null default '0';

//重命名表

   alter table t1 rename t2;
加索引

   > alter table tablename change depno depno int(5) not null;
mysql> alter table tablename add index 索引名 (字段名1[,字段名2 …]);
mysql> alter table tablename add index emp_name (name);
加主关键字的索引

mysql> alter table tablename add primary key(id);
加唯一限制条件的索引

  mysql> alter table tablename add unique emp_name2(cardnumber);
删除某个索引

   mysql>alter table tablename drop index emp_name;
修改表:

增加字段:

   mysql> alter table table_name add field_name field_type;
修改原字段名称及类型:

   mysql> alter table table_name change old_field_name new_field_name field_type;
删除字段:

   mysql> alter table table_name drop field_name;
  
  
   alter table 语句
alter table 语句用于在已有的表中添加、修改或删除列。

sql alter table 语法
如需在表中添加列,请使用下列语法:

alter table table_name
add column_name datatype
要删除表中的列,请使用下列语法:

alter table table_name
drop column column_name
注释:某些系统不允许这种在数据库表中删除列的方式 (drop column column_name)。

要改变表中列的数据类型,请使用下列语法:

alter table table_name
alter column column_name datatype
原始的表 (用在例子中的):
persons 表:

id lastname firstname address city
1 adams john oxford street london
2 bush george fifth avenue new york
3 carter thomas changan street beijing
sql alter table 实例
现在,我们希望在表 "persons" 中添加一个名为 "birthday" 的新列。

我们使用下列 sql 语句:

alter table persons
add birthday date
请注意,新列 "birthday" 的类型是 date,可以存放日期。数据类型规定列中可以存放的数据的类型。

新的 "persons" 表类似这样:

id lastname firstname address city birthday
1 adams john oxford street london  
2 bush george fifth avenue new york  
3 carter thomas changan street beijing  
改变数据类型实例
现在我们希望改变 "persons" 表中 "birthday" 列的数据类型。

我们使用下列 sql 语句:

alter table persons
alter column birthday year
请注意,"birthday" 列的数据类型是 year,可以存放 2 位或 4 位格式的年份。
drop column 实例
接下来,我们删除 "person" 表中的 "birthday" 列:

alter table person
drop column birthdaypersons 表会成为这样:


   ?>

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to change the personal name in the group on DingTalk_How to modify the personal name in the group on DingTalk How to change the personal name in the group on DingTalk_How to modify the personal name in the group on DingTalk Mar 29, 2024 pm 08:41 PM

1. First open DingTalk. 2. Open the group chat and click the three dots in the upper right corner. 3. Find my nickname in this group. 4. Click to enter to modify and save.

How to delete Xiaohongshu notes How to delete Xiaohongshu notes Mar 21, 2024 pm 08:12 PM

How to delete Xiaohongshu notes? Notes can be edited in the Xiaohongshu APP. Most users don’t know how to delete Xiaohongshu notes. Next, the editor brings users pictures and texts on how to delete Xiaohongshu notes. Tutorial, interested users come and take a look! Xiaohongshu usage tutorial How to delete Xiaohongshu notes 1. First open the Xiaohongshu APP and enter the main page, select [Me] in the lower right corner to enter the special area; 2. Then in the My area, click on the note page shown in the picture below , select the note you want to delete; 3. Enter the note page, click [three dots] in the upper right corner; 4. Finally, the function bar will expand at the bottom, click [Delete] to complete.

What is the difference between HQL and SQL in Hibernate framework? What is the difference between HQL and SQL in Hibernate framework? Apr 17, 2024 pm 02:57 PM

HQL and SQL are compared in the Hibernate framework: HQL (1. Object-oriented syntax, 2. Database-independent queries, 3. Type safety), while SQL directly operates the database (1. Database-independent standards, 2. Complex executable queries and data manipulation).

Is it true that you can be blocked and deleted on WeChat and permanently unable to be added? Is it true that you can be blocked and deleted on WeChat and permanently unable to be added? Apr 08, 2024 am 11:41 AM

1. First of all, it is false to block and delete someone permanently and not add them permanently. If you want to add the other party after you have blocked them and deleted them, you only need the other party's consent. 2. If a user blocks someone, the other party will not be able to send messages to the user, view the user's circle of friends, or make calls with the user. 3. Blocking does not mean deleting the other party from the user's WeChat contact list. 4. If the user deletes the other party from the user's WeChat contact list after blocking them, there is no way to recover after deletion. 5. If the user wants to add the other party as a friend again, the other party needs to agree and add the user again.

How to add a TV to Mijia How to add a TV to Mijia Mar 25, 2024 pm 05:00 PM

Many users are increasingly favoring the electronic ecosystem of Xiaomi smart home interconnection in modern life. After connecting to the Mijia APP, you can easily control the connected devices with your mobile phone. However, many users still don’t know how to add Mijia to their homes. app, then this tutorial guide will bring you the specific connection methods and steps, hoping to help everyone in need. 1. After downloading Mijia APP, create or log in to Xiaomi account. 2. Adding method: After the new device is powered on, bring the phone close to the device and turn on the Xiaomi TV. Under normal circumstances, a connection prompt will pop up. Select "OK" to enter the device connection process. If no prompt pops up, you can also add the device manually. The method is: after entering the smart home APP, click the 1st button on the lower left

How to completely delete TikTok chat history How to completely delete TikTok chat history May 07, 2024 am 11:14 AM

1. Open the Douyin app, click [Message] at the bottom of the interface, and click the chat conversation entry that needs to be deleted. 2. Long press any chat record, click [Multiple Select], and check the chat records you want to delete. 3. Click the [Delete] button in the lower right corner and select [Confirm deletion] in the pop-up window to permanently delete these records.

How can I retrieve someone else's deleted comment on Xiaohongshu? Will it be displayed if someone else's comment is deleted? How can I retrieve someone else's deleted comment on Xiaohongshu? Will it be displayed if someone else's comment is deleted? Mar 21, 2024 pm 10:46 PM

Xiaohongshu is a popular social e-commerce platform, and interactive comments between users are an indispensable method of communication on the platform. Occasionally, we may find that our comments have been deleted by others, which can be confusing. 1. How can I retrieve someone else’s deleted comments on Xiaohongshu? When you find that your comments have been deleted, you can first try to directly search for relevant posts or products on the platform to see if you can still find the comment. If the comment is still displayed after being deleted, it may have been deleted by the original post owner. At this time, you can try to contact the original post owner to ask the reason for deleting the comment and request to restore the comment. If a comment has been completely deleted and cannot be found on the original post, the chances of it being reinstated on the platform are relatively slim. You can try other ways

How to send files to others on TikTok? How to delete files sent to others? How to send files to others on TikTok? How to delete files sent to others? Mar 22, 2024 am 08:30 AM

On Douyin, users can not only share their life details and talents, but also interact with other users. In this process, sometimes we need to send files to other users, such as pictures, videos, etc. So, how to send files to others on Douyin? 1. How to send files to others on Douyin? 1. Open Douyin and enter the chat interface where you want to send files. 2. Click the "+" sign in the chat interface and select "File". 3. In the file options, you can choose to send pictures, videos, audio and other files. After selecting the file you want to send, click "Send". 4. Wait for the other party to accept your file. Once the other party accepts it, the file will be transferred successfully. 2. How to delete files sent to others on Douyin? 1. Open Douyin and enter the text you sent.

See all articles