Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear
-- nama : ADAM MALIK -- NIM : 211011401500 -- kelas : 05TPLK002 -- buat database create database latihan_db; -- membuat tabel TblMahasiswa CREATE TABLE TblMahasiswa( Nama nchar(39) not null, NIM nchar(12) not null, Tmplahir nchar(35) not null, Tgllahir datetime not null, Jkelamin nchar(1) not null, Agama nchar(10) not null, Alamat nchar(100) null, Kota nchar(26) null, KodePos nchar(5) null, NoTelp nchar(15) null, ); --buat kolom NIM sebagai primary key dari tabel diatas ALTER TABLE TblMahasiswa add constraint pkey_tblmhs primary key (nim) -- ubah contraint null menjadi not null pada kolom NoTelp ALTER TABLE TblMahasiswa ALTER COLUMN NoTelp nchar(15) not null; -- buat kolom noTelp menjadi unik ALTER TABLE TblMahasiswa add constraint unik_NoTelpMHS unique(NoTelp) -- tambahkan sebuah kolom dengan nama usia bertipe integer dan tidak boleh kosong ALTER TABLE TblMahasiswa add usia int not null; --buat logic untuk cek i put data pada kolom usia harus >=18 alter table TblMahasiswa add constraint chk_usia check(usia>=18); -- hapus logic check usia alter table TblMahasiswa drop constraint chk_usia --buat nilai default dari kolom kota adalah Tangerang Selatan alter table TblMahasiswa add constraint def_kota default 'tangerang selatan' for kota; --tambahkan 10 data kedalam tabel diatas INSERT INTO TblMahasiswa (NIM, Tmplahir, Tgllahir, Jkelamin, Agama, NoTelp, usia) VALUES ('12345', 'Tangerang', '2000-08-05', 'L', 'Islam', '021111', 23) -- Tambahkan 10 data ke dalam tabel diatas

Stuck with a problem? Got Error? Ask AI support!

Copy Clear