专栏首页程序猿SQL2012_创建数据库,创建表,表的内外链接

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),作者:Admin

原文出处及转载信息见文内详细说明,如有侵权,请联系 yunjia_community@tencent.com 删除。

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

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

我来说两句

0 条评论
登录 后参与评论

相关文章

  • SQL Server基础SQL脚本之内外连接、交叉连接;函数、子查询

    代码大概200行左右 本系列,几乎都是代码,记得当时写的时候用的是微软的官方实例数据库AdventureWorks_Data.mdf、AdventureWor...

    赵腰静
  • SQL Server基础SQL脚本之创建架构、排序

    代码420行左右 本系列,几乎都是代码,记得当时写的时候用的是微软的官方实例数据库AdventureWorks_Data.mdf、AdventureWork...

    赵腰静
  • SQL 注入语句特征

    语句特征 1.判断有无注入点 ; and 1=1 and 1=2 2.猜表一般的表的名称无非是admin adminuser user pass passwor...

    赵腰静
  • SQL语句大全,所有的SQL都在这里(1.5万字长文)

    1、说明:创建数据库 CREATE DATABASE database-name

    用户2769421
  • 数据库,单表查询,多表查询,子查询

    语法:select 段落 from 表明 where binary 字段....................................

    小小咸鱼YwY
  • SQL 语句大全

    1、说明:创建数据库 CREATE DATABASE database-name 2、说明:删除数据库 drop database dbname 3、说明:备...

    Hongten
  • mysql数据库

    拾点阳光
  • SQL之经典SQL语句大全

    经典SQL语句大全 一、基础 1、说明:创建数据库 CREATE DATABASE database-name  2、说明:删除数据库 drop databas...

    互联网金融打杂
  • SQL语句大全,所有的SQL都在这里

    1、说明:创建数据库 CREATE DATABASE database-name

    用户6543014
  • SQL语句大全,所有的SQL都在这里(1.5万字长文)

    1、说明:创建数据库 CREATE DATABASE database-name

    帅地

扫码关注云+社区

领取腾讯云代金券