You are on page 1of 4

use master

go

if DB_ID (N'PC3')is not null


drop database PC3
go

CREATE DATABASE PC3


ON PRIMARY
(
name = 'PC3_data01',
filename = 'D:\datos\PC3_data01.mdf',
size = 5MB,
maxsize = 10MB,
filegrowth = 1MB
),
FILEGROUP FG2
(
name = 'PC3_data02',
filename = 'D:\datos\PC3_data02.ndf',
size = 5MB,
maxsize = 50MB,
filegrowth = 5MB
),
(
name = 'PC3_data03',
filename = 'D:\datos\PC3_data03.ndf',
size = 2MB,

maxsize = 20MB,
filegrowth = 2MB
)

LOG ON
(
name = 'PC3_log01',
filename = 'D:\datos\PC3_log01.ldf',
size = 2MB,
maxsize = 20MB,
filegrowth = 2MB
),
(
name = 'PC3_log02',
filename = 'D:\datos\PC3_log02.ldf',
size = 2MB,
maxsize = 20MB,
filegrowth = 2MB
)

GO

use PC3
go
IF OBJECT_ID('tb_tabla01') is not null
drop table tb_tabla01
go

create table tb_tabla01

(
id

int

not null,

Cod_material

char(10)

not null,

Descripcion

nvarchar(200)

null,

fecha_registro

datetime

null,

precio

decimal(6,2) null

)
go
alter table tb_tabla01 add

constraint pk_tb_tabla01 primary key (id)

alter table tb_tabla01 add


(Cod_material)

constraint uq_tb_tabla01_nombre unique

alter table tb_tabla01 add constraint ck_tb_tabla01_descripcion check


(len(descripcion) >= 5)
alter table tb_tabla01 add constraint ck_tb_tabla01_fecha_registro check
(fecha_registro <= getdate())
alter table tb_tabla01 add constraint uq_tb_tabla01_nombre unique (precio)
go
exec sp_helpconstraint tb_tabla01

IF OBJECT_ID('tb_tabla02') is not null


drop table tb_tabla02
go

create table tb_tabla02

(
id
Cod_boleta

int
char(10)

not null,
not null,

fecha_emision

datetime

null,

precio

decimal(6,2) null,

escala

char(02)

null

go
alter table tb_tabla02 add

constraint pk_tb_tabla02 primary key (id)

alter table tb_tabla02 add


(Cod_boleta)

constraint uq_tb_tabla02_Cod_boleta unique

alter table tb_tabla02 add constraint ck_tb_tabla02_fecha_emision check


(fecha_emision <= getdate())
alter table tb_tabla02 add constraint uq_tb_tabla02_nombre unique (precio)
alter table tb_tabla02 add constraint ck_tb_tabla02_escala check (escala =
'01' or escala = '02' or escala = '03')
go
exec sp_helpconstraint tb_tabla02

alter table tb_tabla01


add constraint fk_tb_tabla01_tb_tabla02 foreign key (id) references
tb_tabla01 (id)
go
select * from tb_tabla01
go
select * from tb_tabla02
go