码迷,mamicode.com
首页 > 数据库 > 详细

mysql/sqlserver数据库sql语句练习

时间:2019-10-29 23:23:39      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:query   this   user   sql语句   username   value   last   unknown   time   

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语句练习

标签:query   this   user   sql语句   username   value   last   unknown   time   

原文地址:https://www.cnblogs.com/Ivanhan2019/p/11762098.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!