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

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

原文发布于微信公众号 - 数据库SQL(SQLdba)

原文发表时间:2015-03-07

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏WOLFRAM

向日葵中的数学之美

1923
来自专栏搞前端的李蚊子

Html5模拟通讯录人员排序(sen.js)

// JavaScript Document  var PY_Json_Str = ""; var PY_Str_1 = ""; var PY_Str_...

6356
来自专栏我和未来有约会

简练的视图模型 ViewModel

patterns & practices Developer Center 发布了 Unity Application Block 1.2 for Silver...

2339
来自专栏linux驱动个人学习

高通Audio中ASOC的machine驱动

ASoC被分为Machine、Platform和Codec三大部分,其中的Machine驱动负责Platform和Codec之间的耦合以及部分和设备或板子特定的...

1K4
来自专栏技术之路

wpf键盘记录器

很简单的一个wpf键盘记录器 ? 这个程序我一样用了全局勾子,之前用的都是winform上运行了,前一段时间 在国外的论坛上逛看到了一个wpf能用的就做了一个小...

2055
来自专栏码匠的流水账

聊聊spring cloud的HystrixAutoConfiguration

本文主要研究一下spring cloud的HystrixAutoConfiguration

1122
来自专栏码匠的流水账

spring security reactive获取security context

本文主要研究下reactive模式下的spring security context的获取。

2122
来自专栏一个会写诗的程序员的博客

java.base.jmod

/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/jmods$ jmod list java....

1172
来自专栏专知

2018年SCI期刊最新影响因子排行,最高244,人工智能TPAMI9.455

2018年6月26日,最新的SCI影响因子正式发布,涵盖1万2千篇期刊。CA-Cancer J Clin 依然拔得头筹,其影响因子今年再创新高,达244.585...

1472
来自专栏余生开发

echarts太阳分布图-饼图来回穿梭

var dom = document.getElementById("container");

1412

扫码关注云+社区