mysql学习数据库

下是从命令行中连接MySQL的服务器的简单实例:

mysql -u root -p

输入密码就开始mysql>

开始mysql 使用了

mysql> SHOW databases; 

 

mysql> SHOW TABLES; 

//看表里有哪些列  

mysql> DESCRIBE pet; 

删除数据库.

mysql> DROP DATABASE test;  

一个表中的 FOREIGN KEY 指向另一个表中的

PRIMARY KEY。

 

DECIMAL从MySQL 5.1引入,列的声明语法是DECIMAL(M,D)。在MySQL 5.1中,参量的取值范围如下:

M是数字的最大数(精度)。其范围为1~65(在较旧的MySQL版本中,允许的范围是1~254),M 的默认值是10。
D是小数点右侧数字的数目(标度)。其范围是0~30,但不得超过M。
说明:float占4个字节,double占8个字节,decimail(M,D)占M+2个字节。

如DECIMAL(5,2) 的最大值为9 9 9 9 . 9 9,因为有7 个字节可用。

M 与D 对DECIMAL(M, D) 取值范围的影响

类型说明取值范围(MySQL < 3.23)取值范围(MySQL >= 3.23)

MySQL < 3.23 MySQL >=3.23 
DECIMAL(4, 1) -9.9 到 99.9 -999.9 到 9999.9

DECIMAL(5,1) -99.9 到 999.9 -9999.9 到 99999.9

DECIMAL(6,1) -999.9 到 9999.9 -99999.9 到 999999.9

DECIMAL(6,2) -99.99 到 999.99 -9999.99 到 99999.99

DECIMAL(6,3) -9.999 到 99.999 -999.999 到 9999.999

在MySQL 3.23 及以后的版本中,DECIMAL(M, D) 的取值范围等于早期版本中的DECIMAL(M + 2, D) 的取值范围。

mysql修改表名,列名,列类型,添加表列,删除表列 

alter table test rename test1; --修改表名 

alter table test add  column name varchar(10); --添加表列 

alter table test drop  column name; --删除表列 

alter table test modify address char(10) --修改表列类型 
||alter table test change address address  char(40) 


alter table test change  column address address1 varchar(30)--修改表列名

猜你喜欢

转载自blog.csdn.net/cx1165597739/article/details/83590119