A New Timestamp Value Based on Adding an Interval to an Existing Timestamp Value SQL Syntax

Embed Size (px)

Citation preview

  • 8/9/2019 A New Timestamp Value Based on Adding an Interval to an Existing Timestamp Value SQL Syntax

    1/28

    e function TIMESTAMPADD returns a new timestamp value based on adding an interval

    to an existing timestamp value SQL Syntax:

    TIMESTAMPADD (interval, count, timestamp)Interval:

    One of the follow constants SQL_TSI_FRAC_SECOND,

    SQL_TSI_SECOND, SQL_TSI_MINUTE,SQL_TSI_HOUR, SQL_TSI_DAY, SQL_TSI_WEEK,

    SQL_TSI_MONTH, SQL_TSI_QUARTER, or

    SQL_TSI_YEAR

    Count:

    The count of interval that is added.

    Escape Syntax:{fn TIMESTAMPADD (interval, count, timestamp)}

    Return Type:

    TIMESTAMP

    Alternative Function Names:DATEADD: This is the equivalent from the MS SQL Server.

    Alternative Interval Names: Year yy, yyyyquarter qq, q

    Month mm, m

    dayofyear dy, y

    Day dd, dWeek wk, ww

    Hour hh

    minute mi, nsecond ss, s

    millisecond ms

    Examples:

    * SELECT timestampadd(SQL_TSI_DAY, 21, logdatetime) from mytable

    see also:

    SQL Date Time Functions mbentukan database

    Creating tables (Creating tables)Syntax

    CREATE TABLE (()

    [UNIQUE] [NOT nul] [PRIMARY KEY] [DEFAULT]

    [Referential_constraint_defenition>] [CHECK],()

    [UNIQUE] [NOT NULL] [PRIMARY KEY] [DEFAULT]

    [Referential_constraint_defenition>] [CHECK],

    . . .

  • 8/9/2019 A New Timestamp Value Based on Adding an Interval to an Existing Timestamp Value SQL Syntax

    2/28

    );

    information

    Unique; In that column there should be no similar data.

    Not Null; not be as valuable data in the column null,

    Unique and Not Null; column can be used as a primary key.Default: The default value that will automatically fill in these fields with default data

    every insert operation performed.

    Referential_Constraint_Definition; If the column is a foreign key to another table. Withsyntax FOREIGN KEY REFERENCES

    Example:

    CREATE TABLE Student (

    No_Induk CHAR (8),

    Name CHAR (20),

    Tgl_Lahir DATE,

  • 8/9/2019 A New Timestamp Value Based on Adding an Interval to an Existing Timestamp Value SQL Syntax

    3/28

    Class CHAR (2)

    );CREATE TABLE Mata_Pelajaran (

    Code CHAR (4),

    Name CHAR (20),

  • 8/9/2019 A New Timestamp Value Based on Adding an Interval to an Existing Timestamp Value SQL Syntax

    4/28

    Class CHAR (2)

    );

    CREATE TABLE Value (No_Induk CHAR (8),

    Code CHAR (4),

    Nl_Angka Numbers);

    Creates an index (Creating indices)

    Syntax

    . . .

    [() REFERENCES (),. . . ]

    CREATE INDEX ON ();Example:

    DROP TABLE Student;

    CREATE TABLE Student (No_Induk CHAR (8) PRIMARY KEY,

    Name CHAR (20),Tgl_Lahir DATE,

    Class CHAR (2)

    );

    CREATE INDEX ON nm Student (Name);DROP TABLE Mata_Pelajaran;

    CREATE TABLE Mata_Pelajaran (

    Code CHAR (4) PRIMARY KEY,Name CHAR (20),

    Class CHAR (2)

    );CREATE TABLE Value (

    No_Induk CHAR (8) REFERENCES Student (No_Induk)

    Code CHAR (4) Mata_Pelajaran REFERENCES (Code),Number Value

    );

    Changing tables (Altering tables)

    Syntax

    ALTER TABLE

    [ADD ((),...);][Modify ((),...);]

    Information

    Add: Addition of new columns.

    Modify: Modify existing columns.

    Example:

  • 8/9/2019 A New Timestamp Value Based on Adding an Interval to an Existing Timestamp Value SQL Syntax

    5/28

    ALTER TABLE Student

    ADD (Jenis_Kelamin CHAR (10));

    Removing tables (tables Dropping)Syntax

  • 8/9/2019 A New Timestamp Value Based on Adding an Interval to an Existing Timestamp Value SQL Syntax

    6/28

    DROP TABLE

    DROP INDEXExample:

    DROP TABLE Student;

  • 8/9/2019 A New Timestamp Value Based on Adding an Interval to an Existing Timestamp Value SQL Syntax

    7/28

    DROP INDEX nm;

    II. Data Manipulation Language (DML) / Data Manipulation

    Insertion of data (Inserting)Syntax

    INSERT INTO [(VALUES

    (,,...);

    Example:

    DROP TABLE CASCADE constraints Students;

    CREATE TABLE Student (

    No_Induk CHAR (8) PRIMARY KEY,Name CHAR (20),

    Tgl_Lahir DATE,

    Class CHAR (2)

    );

    INSERT INTO StudentVALUES ('00311217 ',' Wempi Satria ', '02-JAN-1982', '1 ',' Male ');

    INSERT INTO Student

    VALUES ('00311211 ',' Wempi, '03-MAR -1982 ', '1', 'Male');

    INSERT INTO StudentVALUES ('00311210 ',' Satria ', '12-DEC -1982', '1 ',' Woman ');

    Change data (Updating)

    Syntax

    UPDATE

    SET,,

    . . . ,

    [WHERE];

    Example:

    UPDATE StudentsSET No_Induk = '00311216 ', Name =' Wati '

    WHERE No_Induk = '00311210 'and name =' Satria ';

    Delete data (Deletion)Syntax

    DELETE FROMWHERE;

    Example:

    DELETE FROM Students

  • 8/9/2019 A New Timestamp Value Based on Adding an Interval to an Existing Timestamp Value SQL Syntax

    8/28

    WHERE No_Induk = '00311211 ';

    Data Selection (Selection)

    Syntax

    SELECT [*] [,,. . .,]

    [,,. . . ,]

    FROMWHERE

  • 8/9/2019 A New Timestamp Value Based on Adding an Interval to an Existing Timestamp Value SQL Syntax

    9/28

  • 8/9/2019 A New Timestamp Value Based on Adding an Interval to an Existing Timestamp Value SQL Syntax

    10/28

  • 8/9/2019 A New Timestamp Value Based on Adding an Interval to an Existing Timestamp Value SQL Syntax

    11/28

  • 8/9/2019 A New Timestamp Value Based on Adding an Interval to an Existing Timestamp Value SQL Syntax

    12/28

  • 8/9/2019 A New Timestamp Value Based on Adding an Interval to an Existing Timestamp Value SQL Syntax

    13/28

  • 8/9/2019 A New Timestamp Value Based on Adding an Interval to an Existing Timestamp Value SQL Syntax

    14/28

  • 8/9/2019 A New Timestamp Value Based on Adding an Interval to an Existing Timestamp Value SQL Syntax

    15/28

    [INTERNATIONAL][INTERNATIONAL MONTH_BETWEEN ();

    Example:

    SELECT * FROM Students;

    SELECT a.No_Induk, a.Nama, b.Kode, b.Nama, c.Nl_Angka

    FROM Student a, Mata_Pelajaran b, c Values;

    WHERE a.No_Induk = c.No_Induk and b.Kode = c.kode;Creating a virtual table (Creating views)

    Syntax

    CREATE VIEWSELECT U.S.

    FROMWHERE;

    III. Data Control Language (DCI) / Control Data

    Confirmation of storing data in memory to the database (Commit)

    Syntax

    COMMIT [WORK];

    Example:

    INSERT INTO Student

    VALUES ('00311210 ',' Satria ', '15-DEC -1982', '1 ',' Woman ');COMMIT;

    Restores the status before the storage transaction (Rollback)

    Syntax

    ROLLBACK [WORK];

    Granting rights from one user to another user (Grant)

    Syntax

    GRANT

    ON TO[Gran WITH OPTION];

    Abolition of rights granted (REVOKE)

    Syntax

    REVOKE

    FROM;

    Access Specification

  • 8/9/2019 A New Timestamp Value Based on Adding an Interval to an Existing Timestamp Value SQL Syntax

    16/28

    All Privileges; All rights given.

    Select; For selectionUpdate: To change data

    Insert: To insert data

    Delete: To remove dataIV. EXPRESSION

    FROM

    To define the table that becomes a source of data from a command selection

    Example:

    SELECT * FROM StudentWHERE

    To define the conditions of a data retrieval selection command

    Example:

    SELECT * FROM Students WHERE No_Induk = '00311217 ';GROUP BY

    For Grouping data based on the expression of group

    Syntax:

    SELECT

    FROMWHERE

    GROUP BY;

    Example:

    SELECT a.No_Induk, b.Nama, c.Nl_Angka

    FROM Pelajar.a, Value bWHERE a.No_Induk = c.No_Induk and b.kode = c.kode

    GROUP BY a.No_Induk, b.Nama, c.Nl_Angka;

    ORDER BY

    To sort the data selection results

    Syntax:

    SELECT

    FROM

    WHEREORDER BY [DESC];

    Example:

    SELECT * FROM Student

  • 8/9/2019 A New Timestamp Value Based on Adding an Interval to an Existing Timestamp Value SQL Syntax

    17/28

    ORDER BY No_Induk;

    HAVING

    To define limits of selection based on the GROUP BY

    Syntax:

    SELECT

    FROM

    WHEREGROUP BY

    HAVING;

    Example:

    SELECT a.No_Induk, b.Nama, c.Nl_Angka

    FROM Pelajar.a, Value b

    WHERE a.No_Induk = c.No_Induk and b.kode = c.kode

    GROUP BY a.No_Induk, b.Nama, c.Nl_AngkaHAVING Score> 80;

    V. PredicateComparison

    Two terms of comparison with the value data types being compared must be the same

    Equal to, =

    Not the same,

    Smaller,

    Smaller and equal to,> =

    Larger and equal to,

  • 8/9/2019 A New Timestamp Value Based on Adding an Interval to an Existing Timestamp Value SQL Syntax

    18/28

    IN (...)

    IN SELECT ...

    NOT IN (...)

    NOT IN SELECT ...Example:

    SELECT * FROM Student aA.No_Induk WHERE IN (SELECT Value FROM b.No_Induk b);

    LIKE / NOT LIKE

    To compare the data with the pattern / a particular structure, to use one character (_) andstrings (%)

    Syntax:

    ... LIKE... NOT LIKE

    Example:

    SELECT * FROM Student

    WHERE Name LIKE 'We%';

    IS NULL / IS NOT NULL

    To compare a value with NULL

    Syntax:

    ... IS NULL

    ... IS NOT NULLExample:

    SELECT * FROM StudentWHERE IS NULL Classes

    Exist

    To check whether a query has a result or notSyntax:

    ... WHERE exists (SELECT ...)Example:

    SELECT * FROM Student aWHERE exists (

    SELECT FROM b.No_Induk b Value

    WHERE a.No_Induk = b.No_Induk);

    Note

  • 8/9/2019 A New Timestamp Value Based on Adding an Interval to an Existing Timestamp Value SQL Syntax

    19/28

    *

    Keyword from SQL programs is not always the same so we need some modificationsin accordance with the standards used by the manufacturers SQL

    *

    The above syntax can be developed as needed depending on the creativity inprogramming such as the addition sequence looping, functions, procedures, triggers, and

    other - other

    *Above syntax can also be inserted in other applications such as web programming,

    visual programming and relational programming.

    *

    Sign [] is optional

    Other Articles:

    * Function MySQL [Arithmetic] - Basic* Function MySQL [Arithmetic] - Built In

    * National Awakening Blaspheming

    * Background / Background Pas Photos in Photoshop

    * Web Start NetBeans IDE

    Comment

    Add Comment Search

    playas - dizziness | 124.81.104.xxx | 2010-03-24 21:47:22

    halo mas,

    how can I modify an existing constraint value ....

    thanks

    Reply | QuoteRevelation - Remove the existing data of two tables d | 94.246.126.xxx | 2009-03-07

    01:26:30

    Mas I want to ask nh, Are You cranya delete existing data d 2 table with one keypressdelete.untuk printah sqlny yes Are You? Mkasih.

    Reply | Quote

    Wempi - bwt: revelation | 202.93.47.xxx | 2009-03-07 15:06:51aja make it 2x the delete command in the program om the delete button.

    but we can also ngeset directly in the database if it relates to the second table / reference,

    if the mysql enggine use tools that replace the default MyISAM InnoDB.

  • 8/9/2019 A New Timestamp Value Based on Adding an Interval to an Existing Timestamp Value SQL Syntax

    20/28

    If staying for Oracle classmates referencenya key, and set the ON DELETE CASCADE,

    foreign key if it didelete,

    his code examples,

    CREATE TABLE supplier(Supplier_id numeric (10) not null,

    supplier_name VARCHAR2 (50) not null,

    CONTACT_NAME VARCHAR2 (50),Supplier_pk PRIMARY KEY constraint (supplier_id)

    );

    CREATE TABLE products

    (Product_id numeric (10) not null,

    supplier_id numeric (10) not null,

    Constraint fk_supplierFOREIGN KEY (supplier_id)

    REFERENCES supplier (supplier_id)ON DELETE CASCADE

    );

    Reply | Quote

    Word | 114.121.153.xxx | 2010-03-24 22:07:50please cariin formula dates from vb.net

    Reply | Quote

    Abuel - still view? | 118.98.184.xxx | 2008-11-18 14:54:25seblumnya apologize, please enlightenment? I mean it is more likely to update existing

    data in tables VIEW,

    ex: there is a table view which data is taken from a different table and the second onlypartially. What we can update the data in table view? klo can, how the existing data in

    two tables that were not in view? klo there is a more in-depth tutorial about the view,

    thanx ...!Reply | Quote

    Wempi - bwt: Abuel | 202.93.47.xxx | 2008-11-21 18:21:54

    if for the view which can be edited in the insert etc. I did minimal practice, om can walk

    into http://www.fluffycat.com/SQL/Views/ for more details.Reply | Quote

    abuel - manipulation of view? | 124.81.8.xxx | 2008-11-16 14:03:36

    manipulation can not view or update a view directly to the table viewx? sy know thatonly table view actual image of the table.

    Reply | Quote

    Wempi - bwt: abuel | 202.93.47.xxx | 2008-11-17 16:06:21current view is divided into four

    - Deletable view

    - Updatable view

    - Innsertable view

  • 8/9/2019 A New Timestamp Value Based on Adding an Interval to an Existing Timestamp Value SQL Syntax

    21/28

    - Read-only view

    Reply | Quote

    Edisen - How to query tables | 118.136.119.xxx | 2008-11-03 03:44:38mas, Nany Dunk ..

    klu want to query between two tables nulisny pake DDL giman yach?

    thx ...

    Urgent!

    Reply | Quote

    Wempi - bwt: Edisen | 202.93.47.xxx | 2008-11-04 16:54:24sorry still not grasp the purpose wempi om demand, inter-table query how ya?

    possibly creating a view yak mo?

    its syntax, CREATE VIEW [namaview] U.S. [SQLQuery]

    [SQLQuery] make such ordinary SELECT om

    more information can be found here http://blog.its.ac.id/dyah03tc/2007/11/11/modul-2-

    data-definition-language-ddl/ omReply | Quote

    benny | 125.162.82.xxx | 2008-10-14 00:10:24

    ma sample notes in co kwn .........Reply | Quote

    Wempi - bwt: benny | 222.124.130.xxx | 2008-10-14 18:55:39

    sory forgot ya,SELECT * FROM Student a

    A.No_Induk WHERE NOT IN (SELECT Value FROM b.No_Induk b);

    Reply | Quotewindi - the meaning of the expression and predicate | 125.162.89.xxx | 2008-07-05

    18:32:02

    mas. asked nih mo .. mo from the translation of the above I ask what is the purpose and

    expressionContribute a better translation

    Thank you for contributing your translation suggestion to Google Translate.

    Contribute a better translation:mbentukan database
    Creating tables (Creating tables)
    Syntax


    CREATE TABLE (
    ()
    [UNIQUE] [NOT nul] [PRIMARY KEY]

    [DEFAULT]
    [Referential_constraint_defenition>] [CHECK],
    ()
    [UNIQUE] [NOT NULL] [PRIMARY KEY] [DEFAULT]


    [Referential_constraint_defenition>] [CHECK],
    . . .
    );
    information



    Unique; In that column there should be no similar data.
    Not Null; not be

    as valuable data in the column null,
    Unique and Not Null; column can be used as a

  • 8/9/2019 A New Timestamp Value Based on Adding an Interval to an Existing Timestamp Value SQL Syntax

    22/28

    primary key.
    Default: The default value that will automatically fill in these fields

    with default data every insert operation performed.


    Referential_Constraint_Definition; If the column is a foreign key to another table.With syntax FOREIGN KEY REFERENCES

    Example:

    CREATE

    TABLE Student (
    No_Induk CHAR (8),
    Name CHAR (20),
    Tgl_Lahir

    DATE,
    Class CHAR (2)
    );
    CREATE TABLE Mata_Pelajaran (
    CodeCHAR (4),
    Name CHAR (20),
    Class CHAR (2)
    );
    CREATE TABLE

    Value (
    No_Induk CHAR (8),
    Code CHAR (4),
    Nl_Angka Numbers


    );
    Creates an index (Creating indices)
    Syntax

    . . .
    [()REFERENCES (),. . . ]
    CREATE INDEX ON ();
    Example:

    DROP

    TABLE Student;
    CREATE TABLE Student (
    No_Induk CHAR (8) PRIMARY

    KEY,
    Name CHAR (20),
    Tgl_Lahir DATE,
    Class CHAR (2)
    );


    CREATE INDEX ON nm Student (Name);
    DROP TABLE Mata_Pelajaran;
    CREATE TABLE Mata_Pelajaran (
    Code CHAR (4) PRIMARY KEY,


    Name CHAR (20),
    Class CHAR (2)
    );
    CREATE TABLE Value

    (
    No_Induk CHAR (8) REFERENCES Student (No_Induk)
    Code CHAR (4)

    Mata_Pelajaran REFERENCES (Code),
    Number Value
    );
    Changing tables(Altering tables)
    Syntax

    ALTER TABLE
    [ADD ((),...);]


    [Modify ((),...);]
    Information

    Add: Addition of new columns.
    Modify: Modify existing columns.
    Example:

    ALTER TABLE

    Student
    ADD (Jenis_Kelamin CHAR (10));
    Removing tables (tables Dropping)


    Syntax

    DROP TABLE
    DROP INDEX
    Example:


    DROP TABLE Student;
    DROP INDEX nm;
    II. Data ManipulationLanguage (DML) / Data Manipulation
    Insertion of data (Inserting)
    Syntax


    INSERT INTO [(
    VALUES
    (,,...);
    Example:

    DROP

    TABLE CASCADE constraints Students;
    CREATE TABLE Student(
    No_Induk CHAR (8) PRIMARY KEY,
    Name CHAR (20),
    Tgl_Lahir

    DATE,
    Class CHAR (2)
    );

    INSERT INTO Student
    VALUES

    ('00311217 ',' Wempi Satria ', '02-JAN-1982', '1',' Male ');
    INSERT INTO Student
    VALUES

    ('00311211 ',' Wempi, '03-MAR -1982 ', '1',

    'Male');
    INSERT INTO Student
    VALUES ('00311210',' Satria ', '12-DEC -1982', '1 ',' Woman

    ');
    Change data (Updating)
    Syntax

    UPDATE
    SET,
    ,


    . . . ,

    [WHERE];
    Example:

    UPDATE Students
    SET

    No_Induk = '00311216 ', Name =' Wati '
    WHERE No_Induk= '00311210 'and name =' Satria ';
    Delete data (Deletion)


    Syntax

    DELETE FROM
    WHERE;
    Example:


    DELETE FROM Students
    WHERE No_Induk = '00311211 ';
    Data Selection (Selection)
    Syntax

    SELECT [*] [,,. . .,]
    [,,. . . ,]


    FROM
    WHERE
    [INTERNATIONAL]
    [INTERNATIONAL

    MONTH_BETWEEN ();
    Example:

    SELECT * FROM Students;
    SELECT a.No_Induk, a.Nama, b.Kode, b.Nama, c.Nl_Angka
    FROM Student a,

    Mata_Pelajaran b, c Values;
    WHERE a.No_Induk = c.No_Induk and b.Kode =

    c.kode;
    Creating a virtual table (Creating views)
    Syntax

    CREATE

    VIEW
    SELECT U.S.
    FROM
    WHERE;
    III. Data Control Language

  • 8/9/2019 A New Timestamp Value Based on Adding an Interval to an Existing Timestamp Value SQL Syntax

    23/28

    (DCI) / Control Data
    Confirmation of storing data in memory to the database

    (Commit)
    Syntax

    COMMIT [WORK];
    Example:

    INSERT

    INTO Student
    VALUES ('00311210 ',' Satria ', '15-DEC -1982', '1 ',' Woman ');
    COMMIT;
    Restores

    the status before the storage transaction (Rollback)
    Syntax

    ROLLBACK

    [WORK];
    Granting rights from one user to another user (Grant)
    Syntax

    GRANT
    ON TO
    [Gran WITH OPTION];
    Abolition of rights granted

    (REVOKE)
    Syntax

    REVOKE
    FROM;
    Access Specification



    All Privileges; All rights given.
    Select; For selection
    Update: Tochange data
    Insert: To insert data
    Delete: To remove data
    IV.

    EXPRESSION
    FROM

    To define the table that becomes a source of data

    from a command selection
    Example:

    SELECT * FROM Student


    WHERE

    To define the conditions of a data retrieval selection command
    Example:

    SELECT * FROM Students WHERE No_Induk =

    '00311217 ';
    GROUP BY

    For Grouping data based on the

    expression of group
    Syntax:

    SELECT
    FROM
    WHERE


    GROUP BY;
    Example:

    SELECT a.No_Induk, b.Nama, c.Nl_Angka
    FROM Pelajar.a, Value b
    WHERE a.No_Induk = c.No_Induk and b.kode =

    c.kode
    GROUP BY a.No_Induk, b.Nama, c.Nl_Angka;
    ORDER BY

    To sort the data selection results
    Syntax:

    SELECT
    FROM


    WHERE
    ORDER BY [DESC];
    Example:

    SELECT * FROM

    Student
    ORDER BY No_Induk;
    HAVING

    To define limits of

    selection based on the GROUP BY
    Syntax:

    SELECT
    FROM
    WHERE
    GROUP BY
    HAVING;
    Example:

    SELECT

    a.No_Induk, b.Nama, c.Nl_Angka
    FROM Pelajar.a, Value b
    WHERE

    a.No_Induk = c.No_Induk and b.kode = c.kode
    GROUP BY a.No_Induk, b.Nama,c.Nl_Angka
    HAVING Score> 80;
    V. Predicate
    Comparison


    Two terms of comparison with the value data types being compared must be the

    same

    Equal to, =
    Not the same,
    Smaller, <
    Larger>
    Smaller and equal to,> =
    Larger and equal to,