In general, SQL consists of two languages, namely Data Definition Language (DDL) and Data Manipulation Language (DML). DML is used to manipulate existing data in a table. Common commands are:
- SELECT to display the data.
- INSERT to add new data.
- UPDATE to change the existing data.
- DELETE to delete the data.
- SELECT [nama_tabel|alias.]nama_field1 [AS alias1] [, nama_field2, ...] FROM nama_tabel1 [AS alias1] [INNER|LEFT|RIGHT JOIN tabel2 ON kondisi_penghubung] [, nama_tabel3 [AS alias3], ...] [WHERE kondisi] [ORDER BY nama_field1 [ASC|DESC][, nama_field2 [ASC|DESC], ...]] [GROUP BY nama_field1[, nama_field2, ...]] [HAVING kondisi_aggregat]
Some have SMBD aggregate functions, namely the specific functions that involve a group of data (aggregate). In general, aggregate functions are:
SUM to calculate the total nominal data
COUNT to count the number of times the data
AVG to calculate the average group data
MAX and MIN to get the maximum value / minimum of a group of data.
Aggregate function used in the SELECT. Requirements for aggregate functions are placed in the HAVING, not WHERE.
Implementation of DDL and DML is different for each database management system (SMBD).
CREATE is used to create database objects and database. SQL is commonly used are:
CREATE DATABASE nama_basis_data
CREATE DATABASE to create a new database.
CREATE TABLE nama_tabel
CREATE TABLE create a new table on the basis of current data. In general, this command has the form
CREATE TABLE [nama_tabel]
(
nama_field1 tipe_data [constraints] [,
nama_field2 tipe_data,
...]
)
or
CREATE TABLE [nama_tabel]
(
nama_field1 tipe_data [,
nama_field2 tipe_data,
...]
[CONSTRAINT nama_field constraints]
)
with:
nama_field is the name of the column (field) which will be made. Some database management systems allow the use of spaces and characters in the name column nonhuruf.
depending on the implementation tipe_data database management system. For example, in MySQL, can be a data type VARCHAR, TEXT, BLOB, ENUM, and so on.
constraints are constraints that are given for each column. This also depends on the implementation of database management systems, such as NOT NULL, UNIQUE, and so on. This can be used to define the primary key (primary key) and foreign keys (foreign keys).
One table may not have a primary key at all, but it is advisable to define at least one column as primary key.
Example:
CREATE TABLE users
(
username VARCHAR (30) CONSTRAINT PRIMARY KEY,
passwd VARCHAR (20) NOT NULL,
tanggal_lahir DATETIME
);
No comments:
Post a Comment