前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SQL2012_创建数据库,创建表,表的内外链接

SQL2012_创建数据库,创建表,表的内外链接

作者头像
赵腰静
发布2018-03-09 12:07:58
1.9K0
发布2018-03-09 12:07:58
举报
文章被收录于专栏:程序猿

create table a1(

aid int constraint PK_a primary key,

age int check(age between 27 and 80),

sex int check(sex in('M','F')),

tel nvarchar(20) check(tel like'1[3,5,7,8][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]')

)

create table b2(

f nvarchar(10)

)

create rule R as @f like 'Y%'

sp_bindrule 'R','b2.f'

insert into b2 values('you')

select * from b2

sp_unbindrule 'b2.f'

drop rule R

create type HAHA from int not null

create table F(hj HAHA )

insert into F values(23)

create synonym HIHI for AdventureWorks.HumanResources.Department

select * from HIHI

create partition function GG(int) as range left for values(30,70,90)

create partition function JK(date) as range right for values('2001-09-09','2003-06-09')

---------------------------------

if exists(select * from sys.databases where name='SchDB')

drop database SchDB

create database SchDB on primary(

name='S_DB',filename='D:\S_DB.mdf',size=5mb,maxsize=100mb,filegrowth=10%

),( name='S_DB_N_1',filename='D:\S_DB_N_1.ndf',size=1mb,maxsize=50mb,filegrowth=1mb)

,( name='S_DB_N_2',filename='D:\S_DB_N_2.ndf',size=1mb,maxsize=50mb,filegrowth=1mb)

,filegroup XXX( name='S_DB_N_3',filename='D:\S_DB_N_3.ndf',size=1mb,maxsize=50mb,filegrowth=1mb)

,( name='S_DB_N_4',filename='D:\S_DB_N_4.ndf',size=1mb,maxsize=50mb,filegrowth=1mb)

,( name='S_DB_N_5',filename='D:\S_DB_N_5.ndf',size=1mb,maxsize=50mb,filegrowth=1mb)

go

alter database HEIHEI add filegroup FG_New

alter database HEIHEI add file(name='S_DB_N_7',filename='D:\S_DB_N_7.ndf')to filegroup FG_New

alter partition scheme SC next used FG_New

alter partition function GG() split range(90)

use AdventureWorks

select * from HumanResources.Employee

select e.EmployeeID,e.Title,m.ManagerID,m.Title

from HumanResources.Employee e join HumanResources.Employee m

on e.EmployeeID=m.EmployeeID

select e.EmployeeID,e.Title,m.ManagerID,m.Title

from HumanResources.Employee e , HumanResources.Employee m

where e.EmployeeID=m.EmployeeID

select * from HumanResources.Employee

select * from HumanResources.EmployeeDepartmentHistory

select * from HumanResources.Department

select e.BirthDate,h.PayFrequency,d.Name

from HumanResources.Employee e join HumanResources.EmployeeDepartmentHistory g

on e.EmployeeID=g.EmployeeID join HumanResources.Department d on

g.DepartmentID=d.DepartmentID join HumanResources.EmployeePayHistory h

on d.DepartmentID=h.EmployeeID

---!eid-20 ?eid

SELECT DISTINCT DepartmentID FROM HumanResources.EmployeeDepartmentHistory

WHERE EmployeeID IN--返回多个结果的时候我们使用 in

(

select EmployeeID from HumanResources.Employee where Title =--返回一个结果的时候 使用的是=

(

SELECT TITLE FROM HumanResources.Employee WHERE EmployeeID=20

)

)

select EmployeeID eid ,Title T into Emp from HumanResources.Employee

select * from Emp

select eid ,T from Emp r

cross apply

(

select * from HumanResources.Employee f where r.eid=f.EmployeeID

) h

------

create table D_tbl(

c_name nvarchar(20) not null,

A_num int not null

)

insert into D_tbl output inserted.* values('Nora',101),

('Bobin',103),('James',107),('Jennifer',109)

create table B_tbl(

c_name nvarchar(20) not null,

L_num int not null

)

insert into B_tbl output inserted.* values('Nora',301),

('Bobin',305),('James',306),('Jenn',308)

select d.c_name,d.A_num,bt.L_num from D_tbl d

cross apply(select * from B_tbl b where d.c_name=b.c_name) bt

select d.c_name,d.A_num,bt.L_num from D_tbl d

outer apply(select * from B_tbl b where d.c_name=b.c_name) bt

select * from D_tbl

union all

select * from B_tbl

select * from D_tbl

union

select * from B_tbl

select * from D_tbl

except

select * from B_tb

-----------------

.mdf n----.ndf -----3--filegroup

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2015-03-07,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 数据库SQL 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
数据库
云数据库为企业提供了完善的关系型数据库、非关系型数据库、分析型数据库和数据库生态工具。您可以通过产品选择和组合搭建,轻松实现高可靠、高可用性、高性能等数据库需求。云数据库服务也可大幅减少您的运维工作量,更专注于业务发展,让企业一站式享受数据上云及分布式架构的技术红利!
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档