mysql/sqlserver数据库sql语句练习
Posted 梦回第四帝国
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql/sqlserver数据库sql语句练习相关的知识,希望对你有一定的参考价值。
1、在test数据库上建表
create table DemoTable(Name VarChar(20),Age VarChar(3));
create table ThisTable(Firstname Text,Lastname Text);
mysql:
mysql> create Table get0(Word nvarchar(31) NOT NULL,Comment nvarchar(50) NOT NULL);
mysql报错的写法:
mysql> create Table get0(Word nvarchar(31) COLLATE Chinese_PRC_CI_AS NOT NULL,Comment nvarchar(50) COLLATE Chinese_PRC_CI_AS NOT NULL);
ERROR 1273 (HY000): Unknown collation: ‘Chinese_PRC_CI_AS‘
mysql> create Table get(Word nvarchar(31) NOT NULL,Comment nvarchar(50) 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 ‘get(Word nvarchar(31) NOT NULL,Comment nvarchar(50) NOT NULL)‘ at line 1
mysql> CREATE TABLE OFFICES(OfficeID nvarchar(4),OfficeName nvarchar(10));
mysql> create Table Singer(SingerID int AUTO_INCREMENT not NULL,SingerName nvarchar(31) NOT NULL,Birthday datetime not null,PRIMARY KEY (SingerID ASC));
IDENTITY、COLLATE Chinese_PRC_CI_AS是sql server的写法:
create Table Singer(SingerID int IDENTITY(1,1) not NULL,SingerName nvarchar(31) COLLATE Chinese_PRC_CI_AS NOT NULL,Birthday datetime not null);
create Table userphoto(ID int IDENTITY(1,1) not NULL,UserName nvarchar(31) COLLATE Chinese_PRC_CI_AS NOT NULL,Old int not null,photo image);
create Table get(Word nvarchar(31) COLLATE Chinese_PRC_CI_AS NOT NULL,Comment nvarchar(50) COLLATE Chinese_PRC_CI_AS NOT NULL);
2、在test数据库的表中加入记录、更新记录
Insert into DemoTable(Name,Age)Values(‘韩Ivan‘,27);
Insert into get0(Word,Comment)Values(‘poet‘,‘诗人‘);
mysql> Insert into Singer(SingerID,SingerName,Birthday)Values(1,‘张柏芝‘,‘1980-5-24 0:00:00‘);
mysql> Insert into Singer(SingerName,Birthday)Values(‘Ivan‘,‘1960-5-24 0:00:00‘);
Query OK, 1 row affected (0.00 sec)
mysql> select * from Singer;
+----------+------------+---------------------+
| SingerID | SingerName | Birthday |
+----------+------------+---------------------+
| 1 | 张柏芝 | 1980-05-24 00:00:00 |
| 2 | Ivan | 1960-05-24 00:00:00 |
+----------+------------+---------------------+
2 rows in set (0.00 sec)
mysql> update Singer set SingerName=‘刘德华‘,Birthday=‘1961-9-27 0:00:00‘ where SingerID=2;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from Singer;
+----------+------------+---------------------+
| SingerID | SingerName | Birthday |
+----------+------------+---------------------+
| 1 | 张柏芝 | 1980-05-24 00:00:00 |
| 2 | 刘德华 | 1961-09-27 00:00:00 |
+----------+------------+---------------------+
2 rows in set (0.00 sec)
以上是关于mysql/sqlserver数据库sql语句练习的主要内容,如果未能解决你的问题,请参考以下文章