SQL server语法使用

目录、

  1. 创建数据库
  2. 创建表
  3. 插入数据
  4. 查询

1.创建数据库

--创建数据库
create database db_Product
go

--使用数据库
use db_Product
go

2、创建

--创建商品类型表
create table GoodsType
(
    IO int primary key identity(1,1),
    typename varchar(10)not null
)
go
--创建商品信息表
create table Goods
(
    Id int primary key identity(1,1),
    Typeld int foreign key references GoodsType(IO),
    Name varchar(20)not null,
    Price decimal(10,2) not null,
    ProductionDate datetime not null,
    Amount int not null
)
go

3、插入数据

insert into GoodsType values
('家电'),
('电子'),
('食品'),
('生活用品')

insert into Goods values 
('1','冰箱',3344,'2017-06-03',100),
('1','电视',1777,'2016-06-03',100),
('1','微波炉',333,'2017-02-26',100),
('2','手机',4500,'2017-05-07',100),
('2','显示器',1777,'2016-12-04',100),
('2','主机',1500,'2017-03-09',100),
('3','老干妈',9,'2017-07-06',100),
('3','爽口榨菜',3.6,'2017-06-08',100)

4、查

select * from GoodsType
select * from Goods

猜你喜欢

转载自www.cnblogs.com/nongzihong/p/10142032.html