您好,登錄后才能下訂單哦!
今天小編給大家分享一下怎么創建一個創建MySQL數據庫中的datetime類型的相關知識點,內容詳細,邏輯清晰,相信大部分人都還太了解這方面的知識,所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。
環境系統平臺:Microsoft Windows (64-bit) 10版本:4.5
瀚高數據庫中支持使用以下語句創建用戶定義的數據類型:
CREATE DOMAIN
:它創建了一個用戶定義的數據類型,可以有可選的約束,基于其他基本類型,實質是定義一個域。
CREATE TYPE
:它通常用于使用存儲過程創建復合類型(兩種或多種數據類型混合的數據類型)。
假如有以下表結構:
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
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 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類型”這篇文章的所有內容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會為大家更新不同的知識,如果還想學習更多的知識,請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。