如何創(chuàng)建一個(gè)創(chuàng)建MySQL數(shù)據(jù)庫(kù)中的datetime類型
環(huán)境系統(tǒng)平臺(tái):Microsoft Windows (64-bit) 10版本:4.5
瀚高數(shù)據(jù)庫(kù)中支持使用以下語(yǔ)句創(chuàng)建用戶定義的數(shù)據(jù)類型:
?CREATE DOMAIN?
:它創(chuàng)建了一個(gè)用戶定義的數(shù)據(jù)類型,可以有可選的約束,基于其他基本類型,實(shí)質(zhì)是定義一個(gè)域。?CREATE TYPE
?:它通常用于使用存儲(chǔ)過(guò)程創(chuàng)建復(fù)合類型(兩種或多種數(shù)據(jù)類型混合的數(shù)據(jù)類型)。
一、domain用法及示例
假如有以下表結(jié)構(gòu):
create table test_domain (id varchar,md5 text not null check(length(md5)=32));
其中md5列的類型及約束,可以定義一個(gè)domain來(lái)抽象,如下:
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
二、創(chuàng)建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
創(chuàng)建示例:
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);
到此這篇關(guān)于如何創(chuàng)建一個(gè)創(chuàng)建MySQL數(shù)據(jù)庫(kù)中的datetime類型的文章就介紹到這了,更多相關(guān)創(chuàng)建datetime類型內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
mysql和oracle默認(rèn)排序的方法 - 不指定order by
這篇文章主要介紹了mysql和oracle默認(rèn)排序的方法 - 不指定order by。具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07mysql自動(dòng)增量備份的實(shí)例方法(本地備份與遠(yuǎn)程備份)
mysql自動(dòng)增量備份的例子(本地備份與遠(yuǎn)程備份),有需要的朋友可以參考下2013-02-02CentOS 7.2下MySQL的安裝與相關(guān)配置
最近因?yàn)楣ぷ餍枰?,要在CentOS上安裝MySQL,在安裝的時(shí)候遇到了一點(diǎn)問(wèn)題,花了點(diǎn)時(shí)間解決了,感覺(jué)不管是官網(wǎng)還是網(wǎng)上的一些教程都不夠完整,不能一次性幫新手解決問(wèn)題,于是我就結(jié)合官網(wǎng)和網(wǎng)上的資源整理了下,現(xiàn)在分享給大家,希望對(duì)有需要的朋友們能有所幫助。2016-11-11MYSQL實(shí)現(xiàn)連續(xù)簽到功能斷簽一天從頭開(kāi)始(sql語(yǔ)句)
這篇文章主要介紹了MYSQL實(shí)現(xiàn)連續(xù)簽到功能斷簽一天從頭開(kāi)始,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-05-05mysql如果數(shù)據(jù)不存在,則插入新數(shù)據(jù),否則更新的實(shí)現(xiàn)方法
mysql如果數(shù)據(jù)不存在,則插入新數(shù)據(jù),否則更新的實(shí)現(xiàn)方法2011-11-11MySQL占用內(nèi)存較大與CPU過(guò)高測(cè)試與解決辦法
為了裝mysql環(huán)境測(cè)試,裝上后發(fā)現(xiàn)啟動(dòng)后MySQL占用內(nèi)存了很大,達(dá)8百多兆。網(wǎng)上搜索了一下,得到高人指點(diǎn)my.ini。再也沒(méi)見(jiàn)再詳細(xì)的了..只好打開(kāi)my.ini逐行的啃,雖然英文差了點(diǎn),不過(guò)多少M(fèi)還是看得明的2018-03-03一文搞清楚MySQL count(*)、count(1)、count(col)區(qū)別
本文主要介紹了MySQL count(*)、count(1)、count(col)區(qū)別,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03