Linguagem sql

986 views

Published on

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
986
On SlideShare
0
From Embeds
0
Number of Embeds
34
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Linguagem sql

  1. 1. Linguagem SQL g gPROGRAMAÇÃO DE SISTEMAS  ÁINFORMÁTICOS
  2. 2. Linguagem SQLA linguagem SQL pode‐se dividir essencialmente  em quatro grupos de comandos q g p DDL – Data Definition Language (CREATE, ALTER, DROP ) DML – Data Manipulation Language (INSERT, UPDATE, DELETE, SELECT) DCL – Data Control Language (GRANT, REVOKE) DTL – Data Transation Language (BEGIN WORK, COMMIT, ROLLBACK)
  3. 3. DDL Data Definition Language CREATE  {DATABASE | TABLES | INDEX | VIEWS} DROP  {DATABASE | TABLES | INDEX | VIEWS} ALTER TABLE RENAME TABLE
  4. 4. CREATE DATABASE SyntaxCREATE DATABASE  [IF NOT EXISTS] db_name [ [create_specification [, create_specification]  p f [, p f ] ...]create_specification:    [DEFAULT] CHARACTER  SET charset_name SET charset name | [DEFAULT] COLLATE  collation_namehttp://dev.mysql.com/doc/refman/5.0/en/create ‐database.html d t b ht l
  5. 5. CREATE TABLE SyntaxCREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)]    CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl name [(create definition )]     [table_options] [select_statement] create_definition:     column_definition| [CONSTRAINT [symbol]] PRIMARY KEY [index_type] (index_col_name,...)  | KEY [index_name] [index_type] (index_col_name,...)  | INDEX [index_name] [index_type] (index_col_name,...)  | [CONSTRAINT [symbol]] UNIQUE [INDEX]  [index_name] [index_type]  (index_col_name,...)  | [FULLTEXT|SPATIAL] [INDEX] [index_name] (index_col_name,...)  | [FULLTEXT|SPATIAL] [INDEX] [index name] (index col name, )  | [CONSTRAINT [symbol]] FOREIGN KEY        [index_name] (index_col_name,...)  [reference_definition]  | CHECK (expr)column_definition:    col_name type [NOT NULL | NULL] [DEFAULT  default_value]        [AUTO_INCREMENT] [[PRIMARY] KEY] [COMMENT  string ]         default value]        [AUTO INCREMENT] [[PRIMARY] KEY] [COMMENT string]         [reference_definition] http://dev.mysql.com/doc/refman/5.0/en/create table.htmhttp://dev mysql com/doc/refman/5 0/en/create‐table htm
  6. 6. CREATE INDEX SyntaxCREATE [UNIQUE|FULLTEXT|SPATIAL] INDEX  index_name [index_type]    ON tbl_name index name [index type]    ON tbl name (index_col_name,...)index_col_name:     col_name col name [(length)] [ASC | DESC]http://dev.mysql.com/doc/refman/5.0/en/create ‐index.html
  7. 7. CREATE VIEW SyntaxCREATE [OR REPLACE] [ALGORITHM =  {UNDEFINED | MERGE | TEMPTABLE}]     VIEW view_name [(column_list)]    AS  select_statement select statement [WITH [CASCADED |  LOCAL] CHECK OPTION]http://dev.mysql.com/doc/refman/5.0/en/create p // y q / / /5 / / ‐view.html
  8. 8. DROP Syntax DROP {DATABASE | SCHEMA} [IF EXISTS]  db_name DROP INDEX index_name ON tbl_name DROP [TEMPORARY] TABLE [IF EXISTS]     tbl_name [  tbl tbl [, tbl_name] ...    [RESTRICT |  ]      [RESTRICT |  CASCADE] DROP VIEW [IF EXISTS]    view_name [,  DROP VIEW [IF EXISTS]    view name [   view_name] ...    [RESTRICT | CASCADE]http://dev.mysql.com/doc/refman/5.0/en/sql‐ syntax‐data‐definition.html y
  9. 9. RENAME TABLE Syntax RENAME {DATABASE | SCHEMA} db_name RENAME {DATABASE | SCHEMA} db name TO new_db_name;  RENAME  TABLE tbl_name TO new_tb _name tb a e O e tbl a e [, tbl_name2 TO new_tbl_name2] ... 
  10. 10. DML Data Manipulation Language INSERT DELETE UPDATE LOAD DATA INFILE SELECT UNION
  11. 11. INSERT Syntax INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY]  [IGNORE]    [INTO] tbl_name [(col_name,...)]    VALUES  ({expr | DEFAULT} ) ( )     [ ON DUPLICATE KEY  | DEFAULT},...),(...),...    [ ON DUPLICATE KEY  UPDATE col_name=expr, ... ] INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY]  [IGNORE]    [INTO] tbl_name SET  l [IGNORE]    [INTO] tbl SET col_name={expr |  { DEFAULT}, ...    [ ON DUPLICATE KEY UPDATE  col_name=expr, ... ] INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY]  [IGNORE]    [INTO] tbl_name [(col_name,...)]    SELECT ...
  12. 12. DELETE SyntaxDELETE [LOW_PRIORITY] [QUICK] [IGNORE]  FROM tbl_name FROM tbl name [WHERE  where_definition]       [ORDER BY ...]       [LIMIT  row_count] row count]
  13. 13. UPDATE SyntaxUPDATE [LOW_PRIORITY] [IGNORE] tbl_name SET col_name1=expr1 [, col_name2=expr2 ]     SET col name1=expr1 [  col name2=expr2 ...]     [WHERE where_definition]    [ORDER BY ...]     [LIMIT row_count] [LIMIT row count]
  14. 14. LOAD DATA INFILE SyntaxLOAD DATA [LOW_PRIORITY | CONCURRENT]  [ [LOCAL] INFILE file_name.txt    [REPLACE |  ] f [ | IGNORE]    INTO TABLE tbl_name [FIELDS         [ [TERMINATED BY t]        [[OPTIONALLY]  ] [[ ] ENCLOSED BY ]        [ESCAPED BY  ]    ]     [LINES         [STARTING BY ]             [TERMINATED BY n]    ]    [IGNORE number LINES]    [(col_name,...)]
  15. 15. SELECT SyntaxSELECT    [ALL | DISTINCT | DISTINCTROW ]      [HIGH_PRIORITY]      [STRAIGHT_JOIN]       [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]      [SQL_CACHE |  SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]select_expr, ...    [INTO OUTFILE file_name export_options | INTO DUMPFILE  file_name]    [FROM table_references[WHERE where_definition]      [GROUP BY {col_name[GROUP BY {col name | expr | position} [ASC | DESC]    [WITH  | position} [ASC | DESC], ... [WITH  ROLLUP]]      [HAVING where_definition]      [ORDER BY {col_name[ORDER BY {col name | expr | position}  [ASC | DESC]    ]       | position}  [ASC | DESC] , ...]      [LIMIT {[offset,] row_count | row_count OFFSET offset}]      [PROCEDURE procedure_name(argument_list)]      [FOR UPDATE | LOCK IN SHARE MODE]]
  16. 16. UNION Syntax SELECT ...UNION [ALL | DISTINCT] SELECT ...  [UNION [ALL | DISTINCT]    SELECT ...] SELECT  ]

×