日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

MySQL各种类型实验

發布時間:2024/1/17 数据库 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MySQL各种类型实验 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

實驗一:整數

-- 測試一 create database test;-- 新建數據庫,如果已經有了就不需要再創建了 USE test;-- 打開數據庫 drop table if exists test1;-- 如果存在表test1則刪除 create table TEST1(-- 新建表test1 a INT-- 表test1只有一個a列 ); insert into test1 values(123456);-- 向表test1中插入元素 select * from test1;-- 查詢表中全部內容

注: -- 行注釋減減加空格表示行注釋

-- 測試二 drop table if exists test2; create table TEST2( a INT(11) ); insert into test2 values(123456); select * from test2; -- 測試三 USE test; drop table if exists test3; create table TEST3( a INT(11) zerofill ); insert into test3 values(123456); select * from test3;

INT后面括號的數表示顯示寬度,不是占多少字節;
zerofill填充0,在Navicat中顯示不出零,在控制臺能正常顯示并看到填充的0

2.實驗二:實數

use test; drop table if exists test4; CREATE TABLE test4( c1 float(10,2),-- 長度是10小數占兩位小數點不占位 c2 decimal(10,2) );insert into test4 VALUES (131072.32,131072.32); insert into test4 VALUES (131072.5678,131072.1234);select * from test4;

decimal比較精確,當涉及到錢的時候通常用這種類型
3.時間和時間戳

use test;drop table if exists test5; CREATE TABLE test5( c1 datetime, c2 timestamp, c3 char(10) );insert into test5 VALUES (now(),CURRENT_TIMESTAMP,'布朗'); -- now()計算機系統的當前時間 -- current_timestamp當前時間戳 insert into test5 VALUES ('1998-10-05 10:15:25',CURRENT_TIMESTAMP,'小布朗');update test5 set c3='馬丁·路德'where c3 = '小布朗';-- 修改命令select * from test5;

若定義一個字段為timestamp類型,這個字段的時間數據會隨著其他字段修改的時候自動刷新,所以這個數據類型的字段可以存放這條記錄最后被修改的時間
4.字符串類型

-- 字符串類型測試一 use test;drop table if exists test6; CREATE TABLE test6( c1 char(4), c2 varchar(4) )ENGINE=myisam; -- ENGINE=myisam存儲引擎insert into test6 VALUES ('',''); insert into test6 VALUES ('ab','ab'); insert into test6 VALUES ('abcd','abcd');select * from test6; -- 字符串類型測試二 use test;drop table if exists test7; CREATE TABLE test7( v VARCHAR(4), c CHAR(6) );insert into test7 VALUES ('ab ','ab ');select CONCAT(v,'+'),CONCAT(c,'+') from test7; -- concat(,)字符串連接函數

5.復合類型
enum多選一
set多選

-- 自增長列 drop table if exists test9; CREATE TABLE test9( c1 int(11) AUTO_INCREMENT PRIMARY KEY, c2 char(10) )ENGINE = myisam,charset=gbk,AUTO_INCREMENT=10000; insert into test9 value(null,'A'); select * from test9;

代理鍵
自然鍵

-- 布爾型 drop table if exists test10; CREATE TABLE test10( c1 bool,#實際等同于tinyint(1) c2 char(10) )ENGINE = myisam,charset=gbk; insert into test10 value(1,'A'); select * from test10 where c1 = true; use test; -- 存儲文件的目錄?轉義字符 drop table if exists test11; CREATE TABLE test11(path VARCHAR (99)); insert into test11 values('C:\\Program Files\\MySQL Server'); select * from test11;

轉載于:https://www.cnblogs.com/X-JY/p/10870196.html

總結

以上是生活随笔為你收集整理的MySQL各种类型实验的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。