Minggu, 26 Juni 2011

Many tO many

create database sekolah
use sekolah
create table Siswa(
Nim Char(15) Primary key,
Nama Varchar(30),
Alamat Varchar(30),
Jenkel Char(10))

insert into Siswa values('201001030418','Suhardiansyah','Perdagangan','L')
insert into Siswa values('201001030017','Nurlaily Sinaga','Boluk','P')

select*from Siswa

Create table mengambil(
No_Urut Char(2) primary Key,
Kd_matapelajaran char(4)
Constraint F_matapelajaran Foreign key(kd_matapelajaran) references matapelajaran (kd_matpel),
Nisis char(13)
constraint F_Siswa Foreign Key (Nimahs) References Siswa(Nim))

insert into mengambil values('01','0236','201001030065')

select*from mengambil

create table matapelajaran(
kd_matkul Char(4)Primary Key,
Nama_MatpelVarchar(25))

insert into Matapelajaran Values('0236','Delphi')
insert into Matapelajaran Values('0254','Database')
select*from matapelajaran