SQL的学习 サン

今天做了SQL的练习,我才知道什么叫做“坑爹”(这只是一个口头禅,不代表自己的意愿、抱怨什么的)。擦!……书上的SQL是5.0版本,我的是5.1版本了,搞了半天,就是查不出自己的错误是什么。最后终于有一堆的热心观众、朋友帮我解决了这件事,感动啊!T T

要使用自己的数据库,当然必须先要创建自己的数据库。所以现在进入SQL的页面进行数据库的创建等。如下:

这是显现原来系统中所含有的数据库。

<!--EndFragment-->

	mysql> show databases;

 

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

| Database           |

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

| information_schema |

| mysql              |

| test               |

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

3 rows in set (0.04 sec)

这是黑乎乎的屏幕里显示出来的数据库,这些都是系统数据库。

 

这条语句是创建数据库的意思。

	mysql> create database SJpractice
	    -> create database SJpractice;
	ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
	corresponds to your MySQL server version for the right syntax to use near 'create database SJpractice' at line 2
	mysql> create database sj-practiec;
	ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
	corresponds to your MySQL server version for the right syntax to use near '-practiec' at line 1
	mysql> create database sj-practice;
	ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
	corresponds to your MySQL server version for the right syntax to use near '-practice' at line 1
	mysql> create database sjpractice;
	Query OK, 1 row affected (0.00 sec)
	
	mysql> use sjpractice;
	Database changed
	mysql> create table 'VIPMESSAGE'(
	    -> 'id' int not null auto_increment,
	    -> 'name' VARCHAR(45) not null,
	    -> 'pwd' VARCHAR(45) NOT NULL DEFAULT '0',
	    -> PRIMARY KEY('id')
	    -> );
	ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
	corresponds to your MySQL server version for the right syntax to use near ''VIPMESSAGE'(
	'id' int not null auto_increment,
	'name' VARCHAR(45) not null,
	'pw' at line 1
	mysql> create TABLE 'vipmessages'(
	    -> 'id' int not null auto_increment,
	    -> 'name' VARCHAR(45) not null,
	    -> 'pwd' VARCHAR(45) NOT NULL DEFAULT '0',
	    -> PRIMARY KEY('id')
	    -> );
	ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''vipm
	essages'(
	'id' int not null auto_increment,
	'name' VARCHAR(45) not null,
	'p' at line 1
	mysql> CREATE TABLE 'vipmessages' (
	    -> 'id' int not null auto_increment,
	    -> 'name' VARCHAR(45) not null,
	    -> 'pwd' VARCHAR(45) NOT NULL DEFAULT '0',
	    -> PRIMARY KEY('id')
	    -> );
	ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''vipm
	essages' (
	'id' int not null auto_increment,
	'name' VARCHAR(45) not null,
	'' at line 1
	mysql> create table vipmessages (
	    -> id int not null auto_increment,
	    -> name varchar(45) not null,
	    -> pwd varchar(45) not null default '0',
	    ->  primary key ('id')
	    -> );
	ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
	corresponds to your MySQL server version for the right syntax to use near ''id')
)' at line 5

 历经千辛万苦之后,我的数据库终于被建立好了。T T 在之前语法好多都错了……太郁闷了。

 

	mysql> create table vipmessages (
	    -> id int not null auto_increment,
	    -> name varchar(45) not null,
	    -> pwd varchar(45) not null default '0',
	    ->  primary key (id)
	    -> );
	Query OK, 0 rows affected (0.29 sec)

 

这个时候,如果想再多加一条属性的话,就这样来实行。

	mysql> alter table vipmessages;
	Query OK, 0 rows affected (0.00 sec)
	
	mysql> add Email varchar(45) not null;
	ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
	corresponds to your MySQL server version for the right syntax to use near 'add E
	mail varchar(45) not null' at line 1
	mysql> alter table vipmessages,
	    -> add Email varchar(45) not null;
	ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
	corresponds to your MySQL server version for the right syntax to use near 'add Email varchar(45) not null' at line 1

 当然,上面那些全是坑爹的,有的是5.0的版本SQL,有的是我自己语法搞错错了。下面的才是5.1版本正确的:

	mysql> alter table vipmessages
	    -> add Email varchar(45) not null;
	Query OK, 0 rows affected (0.17 sec)
	Records: 0  Duplicates: 0  Warnings: 0

 

嗯,这就是我的数据库中的一张表,当然,这还只是创建阶段,要怎样在里面插入数据,下篇日志再说明。

<!--EndFragment-->
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值