Halaman

Share Up To 110 % - 10% Affiliate Program

TULISAN BERJALAN

UAS Database 11 Oktober 2012

Rabu, 09 Desember 2015

Syntax my SQL



 

    MySQL is an open source program for processing database / data management. to use mysql course we must first learn a command - command / basic syntax of the mysql itself. As for some commands - command / mysql basic syntax is as follows:

Creating database for creating a new database, so it does not apply if the database already exists or you do not have privilege.Sintaksnya: CREATE DATABASE nama_db;

Delete the database for deleting the database and all tables in it. This command does not apply if the database does not exist or you do not have privilege.Sintaksnya: DROP DATABASE nama_db;

Using the default database for making database and reference of the table that you will use. This command does not apply if the database does not exist or you do not have privilege.Sintaksnya: USE nama_db;

Displays the list of existing database for display in the current system itu.Sintaksnya: SHOW DATABASES;

LEVEL TABELMembuat tableUntuk make minimal table you must specify the name and type of columns you want. The simplest syntax (without any other definition) are:

CREATE TABLE nama_tbl (column1 tipekolom1 (), kolom2 tipekolom2 (), ...); Example: You want to create a table with the name of the profile that has column names (of type char, width 20), column age (integer), column jenis_kelamin (type enum , containing M and F). The syntax: TABLE reate profile (name CHAR (20), age INT NOT NULL, jenis_kelamin ENUM ('F', 'M'));

While a rather complete command in creating a table is to include a specific definition. For example a command like this: CREATE TABLE participants (No. SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, name CHAR (30) NOT NULL, BidangStudi ENUM ('TS', 'WD') NOT NULL, PRIMARY KEY (No), INDEX (name, BidangStudi) );

The above command means making table participants with No. column as PRIMARY KEY is a unique index table that can not be duplicated in the attribute AUTO_INCREMENT column that can automatically sort the numbers that filled him. While the Name column and BidangStudi be used as a regular index.

Create an index on the table, add an index on a table that already exists either unique or that biasa.Sintaksnya: CREATE INDEX index_name ON nama_tbl (column_name); CREATE UNIQUE INDEX index_name ON nama_tbl (column_name);

TableUntuk delete delete tables in a specific database. If done then all the contents, indexes and other attributes will terhapus.Sintaksnya: DROP TABLE nama_tbl;

Remove indeksUntuk erase the index on a table.Sintaksnya: DROP INDEX index name ON nama_tbl;

See table information tableUntuk see what's in the database tertentu.Sintaksnya: SHOW TABLES FROM nama_db;

As for seeing the table description or information about the column using the syntax: column_name DESC nama_tbl; or SHOW COLUMNS FROM FROM nama_tbl nama_db;

Obtain or display information from tableUntuk display the contents of the table with the options specified. For example, to display the entire contents of the table is used: SELECT * FROM nama_tbl;

To display only certain columns: SELECT column1, column2, ... FROM nama_tbl;

To display the contents of the column with tertentuSELECT condition WHERE column1 FROM nama_tbl kolom2 = isikolom;

TableDapat structural modifications used to rename a table or alter its structure as manambah columns or indexes, delete columns or indexes, change the type of column and so on. The general syntax: ALTER TABLE nama_tbl action;

To add a new column in a particular place can use: ALTER TABLE nama_tblADD kolom_baru type () definition;

To add kolom_baru integers after column1 used: ALTER TABLE nama_tblADD kolom_baru INT NOT NULL AFTER column1;

To add a new index on a particular table either unique or common: ALTER TABLE ADD INDEX index_name nama_tbl (column_name); ALTER TABLE ADD UNIQUE nama_tbl nama_indeks (column_name); ALTER TABLE nama_tbl nama_indeks ADD PRIMARY KEY (column_name);

To change the column names and definitions, such as changing the name of type integer kolom_baru be new_kolom char with a width of 30 is used: ALTER TABLE nama_tblCHANGE kolom_baru new_kolom CHAR (30) NOT NULL;

To remove a column and all its attributes, eg, remove column1: ALTER TABLE DROP nama_tbl column1;

To remove either a unique index or used: ALTER TABLE DROP nama_tbl index_name; nama_tbl ALTER TABLE DROP PRIMARY KEY;

TableUntuk modification of information in the record or add a new row in the table, the syntax: INSERT INTO nama_tbl (column_name) VALUES (isi_kolom); or INSERT INTO nama_tbl SET column_name = isi_kolom;

For example, to add two rows in the table profile with the content name = deden & sonny and content age = 17 & 18 are: INSERT INTO profile (name, age) VALUES (deden, 17), (sonny, 18) or INSERT INTO profile SET name = deden, age = 17; INSERT INTO SET profile name = sonny, age = 18;

To modify a record or an existing row corresponding to a column. For example to change the deden age to 18 in the above example can be used syntax: UPDATE profiles SET age = 18 WHERE name = qalit;

To delete a record or a specific row in a table. For example, to remove the existing line digunakansintaks ujang name: DELETE FROM WHERE name = ujang profile;

If WHERE is not included in the table then all content will be deleted profile.



Cara Koneksi SQl dengan Foxpro


I will explain how do I connect to the MySQL database Visual FoxPro there are several connections provided by VFP can see in help (F1) 1. SQLCONNECT SQLCONNECT ([cConnectionName | cDataSourceName [, cUserID [, cPassword]] [, lShared]]) example STORE SQLCONNECT ('MyFoxSQLNT', 'myUserID', 'mypassword') TO gnConnHandle IF gnConnHandle <= 0 = MessageBox ("Can not make connection ', 16' SQL Connect Error ') ELSE = MessageBox ('Connection made', 48, 'SQL Connect Message') = SQLDISCONNECT (gnHandle) ENDIF 2.SQLSTRINGCONNECT source = "Driver = MySQL ODBC 5.1 Driver;"; + "SERVER = localhost;"; + "UID = root;"; + "PWD = 12345;"; + "DATABASE = school;"; + "PORT = 3306" pkonek = SQLSTRINGCONNECT (source) if pkonek <0 messagebox ('Connection failed', 16, 'Error') else messagebox ('Connection Successful', 16, 'Success') below are some ways to read FoxPro database with sql server. 1. We must know the location FOLDER say dbf file in D: \ DBF \ 2. We must have Foxfro driver can be downloaded at http://www.microsoft.com/en-us/download/details.aspx?id=14839 3. Then once installed it will automatically read the SQL Server driver to connect to the database    FoxPro or .dbf 4.Selanjutnya enter through SQL Query (I use SQL Server 2005) typed script below    to create Link Server      use master     EXEC master.dbo.sp_addlinkedserver     server = N'LinkDBF ', - Name Link Server Free     @ srvproduct = N'Visual FoxPro 9 '     @ provider = N'VFPOLEDB '     @ datasrc = N'D: \ DBF \ ', @ provstr = N'VFPOLEDB.1'      then Execute 5. Then the Link Server name will be created LinkDBF already be seen in the SQL Server in the Tree Server     Object -> Linked Server will be many tables in accordance with existing .dbf file in the folder D: / DBF 6. How do I select or display the contents of .dbf through Query     for example, want to display the data from the file penjualan.dbf     select * from [LinkDBF] ... sales     display data from file pembelian.dbf     select * from [LinkDBF] ... purchase With the LinkedServer the dbf file if we can fit our will through SQL Query syntax Source: http://rubahmania.wordpress.com              http://nofallen.blogspot.com

Kamis, 11 Oktober 2012

11 OKTOBER 2012

2.Pelajari hasil Fungsi DATEIFF dan GETDATE, dan DATEADD. Jelaskan Sintax dan perbedaan dari ketiga fungsi waktu tersebut.


Datediff : untuk mengembalikan selisih antara datetime1 dan datetime2 dalam jarak yang diberikan


Contoh :
select DATEDIFF (datepart,tanggal_awal,tanggal_akhir)
select DATEDIFF("dd", '08-07-2012','09-07-2012')
select DATEDIFF("dd", '02/04/2011','04/04/2011')



Dateadd : Menambah nilai argumen datetime dengan jarak yang diberikan


Contoh :
SELECT DATEADD(day,11,getdate())
SELECT DATEADD(Month,11,getdate())
SELECT DATEADD(year,11,getdate())


Getdate : mengembalikan tanggal dan waktu saat ini dari mesin yang menjalankan SQL Server


Contoh :
SELECT GATEDATE()



4.Buat View DataPegawai dengan kolom Nomor Pegawai, Nama, Sex, Nikah, Agama, Pendidikan, Jabatan, Kode Kontrak


View_DataPegawai : Nomor Pegawai, Nama, Sex, Nikah, Agama, Pendidikan, Jabatan, Kode Kontrak, tgl1


5. Buat Procedure Hitung Jumlah Bayar untuk menghitung Total Pembayaran yang sudah dilakukan oleh Pegawai tertentu.


Create procedure HitungJumlahBayar @nomer char (10) as select nomer,nama,kodekontrak,sum(tgl1) from vie_DataPegawai where nomer=@nomer


6.  Buat Procedure TampilPendidikan untuk menampilkan data pegawai yang berpendidikan tertentu dari View DataPegawai


create procedure TampilPendidikan @Pendidikan char (20) as select nama,pendidikan from view_DataPegawai where pendidikan = @pendidikan


7.  Buat Function PendidikanPegawai dari NomerPegawai. Penggunaan function ini bisa sebagai berikut : Select PendidikanPegawai(Nomer) from DataPegawai


create function PendidikanPegawai (@nomer char (10))
Returns char (20) as
begin
Return (select pendidikan from pendidikan where kodepd=(select pendidikan from DataPegawai where nomer=@nomer))
end

Rabu, 19 September 2012

DDL DAN DML

1. Data Definition Language ( DDL )
 Is a SQL command for data definition :
· CREATE to create the database , table or index
· ALTER to change the table structure
· DROP to delete the database , table or index
Languange 2. Data Manipulation ( DML )
- Language to access the database
- Language to process database
- Language to call functions aggregation
- Language to query
- The types of queries :
· Simple
· Join
· Multi-storey ( Nested Queries )
Source : http://harisahmad.blogspot.com