怎么创建一个创建MySQL数据库中的datetime类型

发布时间:2022-03-21 09:10:38 作者:iii
来源:亿速云 阅读:759

今天小编给大家分享一下怎么创建一个创建MySQL数据库中的datetime类型的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

环境系统平台:Microsoft Windows (64-bit) 10版本:4.5

瀚高数据库中支持使用以下语句创建用户定义的数据类型:

一、domain用法及示例

假如有以下表结构:

create table test_domain (id varchar,md5 text not null check(length(md5)=32));

其中md5列的类型及约束,可以定义一个domain来抽象,如下:

highgo=# create domain md5 as

highgo-# text not null

highgo-# check (

highgo(#     length(value) = 32

highgo(# );

CREATE DOMAIN

highgo=# 

highgo=# \dD md5

                                  List of domains

 Schema | Name | Type | Collation | Nullable | Default |           Check            

--------+------+------+-----------+----------+---------+----------------------------

 public | md5  | text |           | not null |         | CHECK (length(VALUE) = 32)

(1 row)

highgo=# create table test_domain (id varchar,md5 md5);

CREATE TABLE

highgo=# insert into test_domain values('1','2');

ERROR:  value for domain md5 violates check constraint "md5_check"

highgo=# insert into test_domain values('2','76a2173be6393254e72ffa4d6df1030a');

INSERT 0 1

二、创建MySQL中datetime类型

highgo=# create domain datetime as timestamp without time zone;

highgo=# create table t_time (id int,create_time datetime);

CREATE TABLE

highgo=# \d+ t_time

                                     Table "public.t_time"

   Column    |   Type   | Collation | Nullable | Default | Storage | Stats target | Description 

-------------+----------+-----------+----------+---------+---------+--------------+-------------

 id          | integer  |           |          |         | plain   |              | 

 create_time | datetime |           |          |         | plain   |              | 

Access method: heap

highgo=# insert into t_time values (1,now()),(2,now());

INSERT 0 2

highgo=# 

highgo=# select * from t_time;

 id |        create_time         

----+----------------------------

  1 | 2021-08-03 19:28:11.207324

  2 | 2021-08-03 19:28:11.207324

(2 rows)

三、create type用法及示例

CREATE TYPE name AS

    ( [ attribute_name data_type [ COLLATE collation ] [, ... ] ] )

CREATE TYPE name AS ENUM

    ( [ 'label' [, ... ] ] )

CREATE TYPE name AS RANGE (

    SUBTYPE = subtype

    [ , SUBTYPE_OPCLASS = subtype_operator_class ]

    [ , COLLATION = collation ]

    [ , CANONICAL = canonical_function ]

    [ , SUBTYPE_DIFF = subtype_diff_function ]

)

CREATE TYPE name (

    INPUT = input_function,

    OUTPUT = output_function

    [ , RECEIVE = receive_function ]

    [ , SEND = send_function ]

    [ , TYPMOD_IN = type_modifier_input_function ]

    [ , TYPMOD_OUT = type_modifier_output_function ]

    [ , ANALYZE = analyze_function ]

    [ , INTERNALLENGTH = { internallength | VARIABLE } ]

    [ , PASSEDBYVALUE ]

    [ , ALIGNMENT = alignment ]

    [ , STORAGE = storage ]

    [ , LIKE = like_type ]

    [ , CATEGORY = category ]

    [ , PREFERRED = preferred ]

    [ , DEFAULT = default ]

    [ , ELEMENT = element ]

    [ , DELIMITER = delimiter ]

    [ , COLLATABLE = collatable ]

)

CREATE TYPE name

创建示例:

CREATE TYPE compfoo AS (f1 int, f2 text);

CREATE FUNCTION getfoo() RETURNS SETOF compfoo AS $$

    SELECT fooid, fooname FROM foo

$$ LANGUAGE SQL;

CREATE TYPE bug_status AS ENUM ('new', 'open', 'closed');

CREATE TABLE bug (

    id serial,

    description text,

    status bug_status

);

CREATE TYPE float8_range AS RANGE (subtype = float8, subtype_diff = float8mi);

以上就是“怎么创建一个创建MySQL数据库中的datetime类型”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注亿速云行业资讯频道。

推荐阅读:
  1. Appium中怎么创建一个Note
  2. Python的datetime模块有哪些类型

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

datetime mysql

上一篇:C#多线程相关操作的示例分析

下一篇:C++11中的override有什么用

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》