Kamis, 28 Maret 2013
Program Database SQL
New Query1
create database Mdp
use Mdp
create table tblkategori
(
kodekategori varchar(10),
namakategori varchar(100) not null,
constraint PKtblkategori primary key (kodekategori)
)
create table tblpelanggan
(
kodepelanggan varchar (10),
namapelanggan varchar (100) not null,
constraint PKtblpelanggan primary key (kodepelanggan)
)
create table tblsales
(
kodesales varchar (10),
namasales varchar (100) not null,
constraint PKtblsales primary key (kodesales)
)
create table tblsupplier
(
kodesupplier varchar (10),
namasupplier varchar (100) not null,
constraint PKtblsupplier primary key (kodesupplier)
)
create table tblbarang
(
kodebarang varchar (20),
namabarang varchar (200)null,
jumlahbarang integer not null,
kodekategori varchar (10) not null,
constraint PKtblbarang primary key (kodebarang),
constraint FKtblbarang foreign key (kodekategori) references tblkategori(kodekategori)
)
create table tblpenjualan
(
kodefaktur varchar(20) not null,
kodebarang varchar(20)not null,
kodepelanggan varchar(10)not null,
kodesales varchar(10)not null,
tgljual datetime not null,
jumlahbarang integer not null,
constraint PKtblpenjualan primary key(kodebarang,kodepelanggan),
constraint FKtblpenjualan1 foreign key (kodebarang)references tblbarang(kodebarang),
constraint FKtblpenjualan2 foreign key (kodepelanggan)references tblpelanggan(kodepelanggan),
constraint FKtblpenjualan3 foreign key (kodesales)references tblsales(kodesales)
)
create table tglpembelian
(
kodepembelian varchar(20) not null,
kodebarang varchar (20) not null,
kodesupplier varchar (10) not null,
kodesales varchar(10) not null,
tglbeli datetime not null,
jumlahbeli integer not null,
constraint PKtblpembelian primary key(kodepembelian,kodebarang),
constraint FKtblpembelian1 foreign key (kodebarang)references tblbarang(kodebarang),
constraint FKtblpembelian2 foreign key (kodesupplier)references tblsupplier(kodesupplier),
constraint FKtblpembelian3 foreign key (kodesales)references tblsales(kodesales)
)
select * from tblbarang
select KodeBarang, JumlahBarang from tblbarang
insert into tblkategori values('KK001','Tablet')
insert into tblkategori values('KK002','Smartphone')
insert into tblkategori values('KK003','Notebook')
insert into tblbarang values('KB001','Samsung Galaxy S III',200,'KK001')
insert into tblbarang values('KB002','BlackBarry Gemini',300,'KK002')
insert into tblbarang values('KB003','ACER ASPIRE one Happy',150,'KK003')
insert into tblpelanggan values('KP001','Akbar')
insert into tblpelanggan values('KP002','Jejen')
insert into tblpelanggan values('KP003','Ardi')
insert into tblsales values('KS001','Aldi')
insert into tblsales values('KS002','Tejo')
insert into tblsales values('KS003','Dwiyan')
insert into tblpenjualan values('KJ001','KB002','KP002','KS003',2013-03-16,5)
insert into tblpenjualan values('KJ002','KB001','KP001','KS002',2013-03-18,10)
insert into tblpenjualan values('KJ003','KB003','KP003','KS001',2013-03-20,10)
select* from tblbarang
select* from tblkategori
select* from tblpelanggan
select* from tblsales
select* from tblpenjualan
New Query2
EXEC sp_dbcmptlevel 'mdp','90';
go
ALTER AUTHORIZATION ON DATABASE::mdp TO "sa"
go
use [mdp]
go
EXECUTE AS USER = N'dbo'REVERT
go
Langganan:
Posting Komentar (Atom)

Tidak ada komentar:
Posting Komentar