MyWeb数据库,cantus表
USE [MyWeb]
GO
/****** Object: Table [dbo].[cantus] Script Date: 2017/12/12 12:12:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[cantus](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Serial] [tinyint] NULL,
[Song] [nvarchar](20) NULL,
[Album] [nvarchar](20) NULL,
[Number] [smallint] NULL,
[Date] [date] NULL,
[Writer] [nvarchar](20) NULL,
[Composer] [nvarchar](20) NULL,
[Arranger] [nvarchar](20) NULL,
[Singing] [nvarchar](20) NULL,
[Lyric] [nvarchar](4000) NULL,
CONSTRAINT [PK_cantus] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SQL Server普通查询
select
语法:(查询)
select 列名称 from 表名称
例:
select * from cantus
select Song,Album from cantus
distinct
语法:(去重)
select distinct 列名称 from 表名称
例:
select distinct * from cantus
select distinct Song,Album from cantus
where
语法:(条件)
select 列名称 from 表名称 where 列 运算符 值
例:
select * from cantus where id=1
select Song,Album from cantus where Song='可爱女人'
值:
= 等于
<> 不等于
> 大于
< 小于
>= 大于等于
<= 小于等于
between 在某个范围内
like 搜索某种模式
注释:在某些版本的 SQL 中,操作符 <> 可以写为 !=。
引号的使用
SQL 使用单引号来环绕文本值(大部分数据库系统也接受双引号)。如果是数值,请不要使用引号。
AND & OR 运算符(与 & 或)
select * from cantus where Album='Jay' AND Number=1
select * from cantus where Album='Jay' OR Number=12
select * from cantus where (Album='Jay' OR Number=12) AND Serial=1
order by(后跟列名)
正序:(asc)
select * from cantus order by Number asc
倒序:(desc)
select * from cantus order by Number desc
以逆字母顺序显示 曲目,并以数字顺序显示 专辑数
select * from cantus order by Serial desc,Number asc
insert into
语法:
insert into 表名称 (列1,列2,...) values (值1,值2,...)
例:
insert into cantus (Serial,Song) values (9,'龙卷风')
update
语法:
update 表名称 set 列名称=新值 where 列名称=某值
例:
update cantus set Song='龙卷风' where Serial=9
delete
语法:
delete from 表名称 where 列名称=值
例:
delete from cantus where Song='龙卷风'
全部删除:
delete from cantus
或者:
delete * from cantus
use
语法:
use 数据库名
例:
use MyWeb
create database
语法:
create database 数据库名
例:
create database MyWeb
create table
语法:
create table 表名
(
列名称1 数据类型,
列名称2 数据类型,
列名称3 数据类型,
....
)
例:
create table cantus
(
Id_P int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
)
drop
drop table 表名称
drop database 数据库名
Join
语法:(连接查询)
不用 Join:
select Persons.LastName, Persons.FirstName, Orders.OrderNo
from Persons, Orders
where Persons.Id_P = Orders.Id_P
使用 Join:
select Persons.LastName, Persons.FirstName, Orders.OrderNo
from Persons
inner join Orders
on Persons.Id_P = Orders.Id_P
order by Persons.LastName