sql 更改列数据类型_SQL查询更改列数据类型

sql 更改列数据类型

Datatype of the column in SQL can be changed using the ALTER TABLE command. It can also be used to ADD, DELETE or MODIFY columns in already existing tables. It can also be used to ADD or DROP constraints in the SQL database.

可以使用ALTER TABLE命令更改SQL中列的数据类型。 它也可以用来添加,删除或修改现有表中的列。 它也可以用于在SQL数据库中添加或删除约束。

Here we are going to only talk about changing the datatype of the column.

在这里,我们只讨论改变列的数据类型

For doing the task the following syntax is used,

为了执行此任务,使用了以下语法,

    ALTER TABLE table_name
MODIFY COLUMN column_name datatype;

Let's understand the above-mentioned concept with the help of example.

让我们借助示例来了解上述概念。

Let us consider the table "People".

让我们考虑表“ People”。

SRNAMEAGEBIRTH_YEAR
1Mona451975
2Kanishka182002
3Hardik221998
SR 名称 年龄 出生年
1个 莫娜 45 1975年
2 鹿冢 18 2002年
3 哈迪克 22 1998年

Here we are going to change the datatype for birth_year from int to year datatype.

在这里,我们将birth_year的数据类型从int更改为year数据类型。

SQL Query:

SQL查询:

ALTER TABLE People
MODIFY COLUMN birth_year year;

After the commitment of this program code, the column birth_year is now of type year and can only store birth_year in the two or four-digit format.

提交该程序代码后, birth_year列现在为year类型,并且只能以两位或四位格式存储birth_year 。

翻译自: https://www.includehelp.com/sql/query-to-change-column-datatype.aspx

sql 更改列数据类型

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/543977.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

SpringBoot 时间格式化的 5 种实现方法!

作者 | 王磊来源 | Java中文社群(ID:javacn666)转载请联系授权(微信ID:GG_Stone)在我们日常工作中,时间格式化是一件经常遇到的事儿,所以本文我们就来盘点一下 Spring Boot 中时间格…

java 枚举 示例_Java枚举name()方法及示例

java 枚举 示例枚举类name()方法 (Enum Class name() method) name() method is available in java.lang package. name()方法在java.lang包中可用。 name() method is used to return the name of this enum constants as it is declared in its enum prototype or declaratio…

SpringBoot 解决跨域问题的 5 种方案!

作者 | 磊哥来源 | Java面试真题解析(ID:aimianshi666)转载请联系授权(微信ID:GG_Stone)跨域问题指的是不同站点之间,使用 ajax 无法相互调用的问题。跨域问题本质是浏览器的一种保护机制&#…

Java 中的 Lombok 到底能不能用?

一、摘要Java,作为一款非常热门的编程语言,尽管它有着非常丰富的语言特性,完全面向对象编程,编程高度规范化,但是也有一个最受大家诟病的一个缺点:啰嗦,尤其是当你开发了很多年之后,…

旅行商问题

旅行商问题 (Travelling Salesman problem) This problem can be stated as- "Given n number of cities and a travelling salesman has to visit each city. Then we have to find the shortest tour so that the travelling salesman can visit each and every city on…

清除元素中的子元素html_HTML中的元素简介

清除元素中的子元素htmlAn element is a fundamental component that is used to develop web pages. Generally an element as two components: a starting tag and a closing tag. The content is added in between the starting and closing tags. The ending tag is the sa…

分页 + 模糊查询竟然有坑?

不知道你有没有使用过Mysql的like语句,进行模糊查询?不知道你有没有将查询结果,进行分页处理?模糊查询,加上分页处理,会有意想不到的坑,不信我们继续往下看。我之前提供过一个品牌查询接口&…

导致事务@Transactional失效的5种场景!

作者 | 磊哥来源 | Java面试真题解析(ID:aimianshi666)转载请联系授权(微信ID:GG_Stone)一个程序中不可能没有事务,而 Spring 中,事务的实现方式分为两种:编程式事务和声…

操作系统 cpu调度_CPU调度| 操作系统

操作系统 cpu调度调度标准 (Scheduling Criteria) There are many criteria which have been suggested for comparing the CPU scheduling algorithms. The characteristics which are used for comparison and then used to determine the best algorithms, for this some of…

IOS中KVO模式的解析与应用

最近老翁在项目中多处用到了KVO,深感这种模式的好处。现总结如下: 一、概述 KVO,即:Key-Value Observing,它提供一种机制,当指定的对象的属性被修改后,则对象就会接受到通知。简单的说就是每次指定的被观察…

使用 lambda 实现超强的排序功能

我们在系统开发过程中,对数据排序是很常见的场景。一般来说,我们可以采用两种方式:借助存储系统(SQL、NoSQL、NewSQL 都支持)的排序功能,查询的结果即是排好序的结果查询结果为无序数据,在内存中…

java 的23种设计模式 之单身狗和隔壁老王的故事

2019独角兽企业重金招聘Python工程师标准>>> 觉得代码写的别扭了,回头翻翻java 的23种设计模式。today,额,这么晚了,困了。就弄个最简单的单例模式吧。单例模式:俗称单身狗 package singleton; public class SingleTon { private …

使用python学线性代数_二项式过程| 使用Python的线性代数

使用python学线性代数When we flip a coin, there are two possible outcomes as head or tail. Each outcome has a fixed probability of occurrence. In the case of fair coins, heads and tails each have the same probability of 1/2. In addition, there are cases in …

工作中常见的 6 种设计模式,你用过几种?

前言 哈喽,大家好。平时我们写代码呢,多数情况都是流水线式写代码,基本就可以实现业务逻辑了。如何在写代码中找到乐趣呢,我觉得,最好的方式就是:使用设计模式优化自己的业务代码。今天跟大家聊聊日常工作中…

c#抽象属性_C#中的抽象属性

c#抽象属性C#抽象属性 (C# Abstract properties) An abstract may contain some abstract properties. That can be implemented in derived class. Here we use abstract and override keywords. 抽象可能包含一些抽象属性。 可以在派生类中实现 。 在这里&#xf…

这12款idea插件,能让你代码飞起来!

前言基本上每个程序员都会写代码,但写代码的速度不尽相同。为什么有些人,一天只能写几百行代码?而有些人,一天可以写几千行代码?有没有办法,可以提升开发效率,在相同的时间内,写出更…

node js 开发网站_使用Node JS开发网站

node js 开发网站You will have your own fully functional website running on "localhost" after going through this article. 阅读完本文后,您将在“ localhost”上运行自己的功能齐全的网站 。 Basic knowledge of JavaScript and HTML is a prereq…

hdu 1166 敌兵布阵

Problem DescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地…

Java:LocalDate / LocalDateTime加减时间

在线API参考:LocalTime (Java Platform SE 8 ) 方法介绍 方法1方法1说明plusYears(long years) minusYears(long years) 返回增加/减少了年数的副本plusMonths(long months) minusMonths(long months)返回增加/减少了月数的副本plusWeeks(long weeks) minusWeeks(…