SQL Tutorial

Total Page:16

File Type:pdf, Size:1020Kb

SQL Tutorial SQL Tutorial SQL TUTORIAL Simply Easy Learning by tutorialspoint.com tutorialspoint.com i ABOUT THE TUTORIAL SQL Tutorial SQL is a database computer language designed for the retrieval and management of data in relational database. SQL stands for Structured Query Language. This tutorial will give you quick start with SQL. Audience This reference has been prepared for the beginners to help them understand the basic to advanced concepts related to SQL languages. Prerequisites Before you start doing practice with various types of examples given in this reference, I'm making an assumption that you are already aware about what is database, especially RDBMS and what is a computer programming language. Copyright & Disclaimer Notice All the content and graphics on this tutorial are the property of tutorialspoint.com. Any content from tutorialspoint.com or this tutorial may not be redistributed or reproduced in any way, shape, or form without the written permission of tutorialspoint.com. Failure to do so is a violation of copyright laws. This tutorial may contain inaccuracies or errors and tutorialspoint provides no guarantee regarding the accuracy of the site or its contents including this tutorial. If you discover that the tutorialspoint.com site or this tutorial content contains some errors, please contact us at [email protected] TUTORIALS POINT Simply Easy Learning Table of Content SQL Tutorial ............................................................................. 2 Audience .................................................................................. 2 Prerequisites ............................................................................ 2 Copyright & Disclaimer Notice .................................................. 2 SQL Overview ........................................................................ 15 What is SQL? ........................................................................................... 15 Why SQL? ................................................................................................ 15 History: ..................................................................................................... 16 SQL Process: ........................................................................................... 16 SQL Commands: ...................................................................................... 17 DDL - Data Definition Language: ............................................................. 17 DML - Data Manipulation Language: ........................................................ 17 DCL - Data Control Language: ................................................................. 17 DQL - Data Query Language: .................................................................. 17 SQL RDBMS Concepts .......................................................... 18 What is field? ............................................................................................ 19 What is record, or row? ............................................................................ 19 What is column? ....................................................................................... 19 What is NULL value?................................................................................ 19 SQL Constraints: ...................................................................................... 20 NOT NULL Constraint: ............................................................................. 20 DEFAULT Constraint:............................................................................... 21 Example: .................................................................................................. 21 Drop Default Constraint: ........................................................................... 21 UNIQUE Constraint: ................................................................................. 21 Example: .................................................................................................. 21 DROP a UNIQUE Constraint: ................................................................... 22 PRIMARY Key: ......................................................................................... 22 Create Primary Key: ................................................................................. 22 Delete Primary Key: ................................................................................. 23 FOREIGN Key: ......................................................................................... 24 Example: .................................................................................................. 24 DROP a FOREIGN KEY Constraint: ........................................................ 25 CHECK Constraint: .................................................................................. 25 Example: .................................................................................................. 25 DROP a CHECK Constraint: .................................................................... 25 INDEX: ..................................................................................................... 26 TUTORIALS POINT Simply Easy Learning Example: .................................................................................................. 26 DROP a INDEX Constraint: ...................................................................... 26 Data Integrity: ........................................................................................... 26 Database Normalization ........................................................................... 27 Third Rule of 1NF: .................................................................................... 29 SQL RDBMS Databases ........................................................ 32 MySQL ..................................................................................................... 32 History: ..................................................................................................... 32 Features: .................................................................................................. 33 MS SQL Server ........................................................................................ 33 History: ..................................................................................................... 33 Features: .................................................................................................. 34 ORACLE .................................................................................................. 34 History: ..................................................................................................... 34 Features: .................................................................................................. 35 MS- ACCESS ........................................................................................... 36 Features: .................................................................................................. 36 SQL Syntax ............................................................................ 37 SQL SELECT Statement: ......................................................................... 37 SQL DISTINCT Clause: ........................................................................... 37 SQL WHERE Clause:............................................................................... 37 SQL AND/OR Clause: .............................................................................. 37 SQL IN Clause: ........................................................................................ 38 SQL BETWEEN Clause: .......................................................................... 38 SQL Like Clause: ..................................................................................... 38 SQL ORDER BY Clause: ......................................................................... 38 SQL GROUP BY Clause: ......................................................................... 38 SQL COUNT Clause: ............................................................................... 38 SQL HAVING Clause: .............................................................................. 38 SQL CREATE TABLE Statement: ............................................................ 38 SQL DROP TABLE Statement: ................................................................ 39 SQL CREATE INDEX Statement: ............................................................ 39 SQL DROP INDEX Statement: ................................................................ 39 SQL DESC Statement: ............................................................................. 39 SQL TRUNCATE TABLE Statement: ....................................................... 39 SQL ALTER TABLE Statement: ............................................................... 39 SQL ALTER TABLE Statement (Rename): .............................................. 39 SQL INSERT INTO Statement: ................................................................ 39 SQL UPDATE Statement: ........................................................................ 39 TUTORIALS POINT Simply Easy Learning SQL DELETE Statement: ......................................................................... 40 SQL CREATE DATABASE Statement: .................................................... 40 SQL DROP DATABASE Statement: ........................................................ 40 SQL USE Statement: ............................................................................... 40
Recommended publications
  • Documents and Attachments 57 Chapter 7: Dbamp Stored Procedure Reference
    CData Software, Inc. DBAmp SQL Server Integration with Salesforce.com Version 5.1.6 Copyright © 2021 CData Software, Inc. All rights reserved. Table of Contents Acknowledgments ........................................................................... 7 Chapter 1: Installation/Upgrading ................................................. 8 Upgrading an existing installation ......................................................... 8 Prerequistes ....................................................................................... 9 Running the DBAmp installation file...................................................... 9 Configure the DBAmp provider options ................................................. 9 Connecting DBAmp to SQL Server ...................................................... 10 Verifying the linked server ................................................................. 11 Install the DBAmp Stored Procedures ................................................. 11 Running the DBAmp Configuration Program........................................ 11 Setting up the DBAmp Work Directory ................................................ 12 Enabling xp_cmdshell for DBAmp ....................................................... 13 Pointing DBAmp to your Salesforce Sandbox Instance ......................... 13 Chapter 2: Using DBAMP as a Linked Server ................................ 14 Four Part Object Names .................................................................... 14 SQL versus SOQL .............................................................................
    [Show full text]
  • Cobol/Cobol Database Interface.Htm Copyright © Tutorialspoint.Com
    CCOOBBOOLL -- DDAATTAABBAASSEE IINNTTEERRFFAACCEE http://www.tutorialspoint.com/cobol/cobol_database_interface.htm Copyright © tutorialspoint.com As of now, we have learnt the use of files in COBOL. Now, we will discuss how a COBOL program interacts with DB2. It involves the following terms: Embedded SQL DB2 Application Programming Host Variables SQLCA SQL Queries Cursors Embedded SQL Embedded SQL statements are used in COBOL programs to perform standard SQL operations. Embedded SQL statements are preprocessed by SQL processor before the application program is compiled. COBOL is known as the Host Language. COBOL-DB2 applications are those applications that include both COBOL and DB2. Embedded SQL statements work like normal SQL statements with some minor changes. For example, that output of a query is directed to a predefined set of variables which are referred as Host Variables. An additional INTO clause is placed in the SELECT statement. DB2 Application Programming Following are rules to be followed while coding a COBOL-DB2 program: All the SQL statements must be delimited between EXEC SQL and END-EXEC. SQL statements must be coded in Area B. All the tables that are used in a program must be declared in the Working-Storage Section. This is done by using the INCLUDE statement. All SQL statements other than INCLUDE and DECLARE TABLE must appear in the Procedure Division. Host Variables Host variables are used for receiving data from a table or inserting data in a table. Host variables must be declared for all values that are to be passed between the program and the DB2. They are declared in the Working-Storage Section.
    [Show full text]
  • Database Administrator
    PINELLAS COUNTY SCHOOL DISTRICT, FLORIDA PCSB: 8155 FLSA: Exempt Pay Grade: E08 PTS DATABASE ADMINISTRATOR REPORTS TO: Director, Application Support and Development SUPERVISES: Senior Application Specialist Programmer Analyst QUALIFICATIONS: IT-related bachelor’s degree from an accredited college or university preferably in MIS or a related area plus five (5) years progressively responsible experience in programming, systems analysis, systems design work, database programming experience writing and maintaining complex database objects using Microsoft SQL Server to include three (3) years of information systems project management experience. Database management and experience using DB2, MySQL, SQL Server Integration Services, SQL Server Analysis Services and SQL Server Reporting Services is required. Experience with hardware and applications required; or an equivalent combination of education, training, and related Pinellas County School Board experience. Microsoft technology certification desired in Microsoft Certified Professional (MCP), Microsoft Certified Application Developer (MCAD), Microsoft Certified Solution Developer (MCSD), and/or Microsoft Certified Database Administrator (MCDBA). MAJOR FUNCTION Responsible for creating data structures and database management capabilities to enable the development of application solutions involving operational databases and solutions utilizing business intelligence and data warehousing databases. Accomplishes this with strong troubleshooting, performance tuning skills, strong problem-solving,
    [Show full text]
  • An Array-Oriented Language with Static Rank Polymorphism
    An array-oriented language with static rank polymorphism Justin Slepak, Olin Shivers, and Panagiotis Manolios Northeastern University fjrslepak,shivers,[email protected] Abstract. The array-computational model pioneered by Iverson's lan- guages APL and J offers a simple and expressive solution to the \von Neumann bottleneck." It includes a form of rank, or dimensional, poly- morphism, which renders much of a program's control structure im- plicit by lifting base operators to higher-dimensional array structures. We present the first formal semantics for this model, along with the first static type system that captures the full power of the core language. The formal dynamic semantics of our core language, Remora, illuminates several of the murkier corners of the model. This allows us to resolve some of the model's ad hoc elements in more general, regular ways. Among these, we can generalise the model from SIMD to MIMD computations, by extending the semantics to permit functions to be lifted to higher- dimensional arrays in the same way as their arguments. Our static semantics, a dependent type system of carefully restricted power, is capable of describing array computations whose dimensions cannot be determined statically. The type-checking problem is decidable and the type system is accompanied by the usual soundness theorems. Our type system's principal contribution is that it serves to extract the implicit control structure that provides so much of the language's expres- sive power, making this structure explicitly apparent at compile time. 1 The Promise of Rank Polymorphism Behind every interesting programming language is an interesting model of com- putation.
    [Show full text]
  • 9. SQL FUNDAMENTALS What Is SQL?
    ROHINI COLLEGE OF ENGINEERING & TECHNOLOGY 9. SQL FUNDAMENTALS What is SQL? • SQL stands for Structured Query Language • SQL allows you to access a database • SQL is an ANSI standard computer language • SQL can execute queries against a database • SQL can retrieve data from a database • SQL can insert new records in a database • SQL can delete records from a database • SQL can update records in a database • SQL is easy to learn SQL is an ANSI (American National Standards Institute) standard computer language for accessing and manipulating database systems. SQL statements are used to retrieve and update data in a database. • SQL works with database programs like MS Access, DB2, Informix, MS SQL Server, Oracle, Sybase, etc. There are many different versions of the SQL language, but to be in compliance with the ANSI standard, they must support the same major keywords in a similar manner (such as SELECT, UPDATE, DELETE, INSERT, WHERE, and others). SQL Database Tables • A database most often contains one or more tables. Each table is identified by a name (e.g. "Customers" or "Orders"). Tables contain records (rows) with data. Below is an example of a table called "Persons": CS8492-DATABASE MANAGEMENT SYSTEMS ROHINI COLLEGE OF ENGINEERING & TECHNOLOGY SQL Language types: Structured Query Language(SQL) as we all know is the database language by the use of which we can perform certain operations on the existing database and also we can use this language to create a database. SQL uses certain commands like Create, Drop, Insert, etc. to carry out the required tasks. These SQL commands are mainly categorized into four categories as: 1.
    [Show full text]
  • Embedded Database Logic
    Embedded Database Logic Lecture #15 Database Systems Andy Pavlo 15-445/15-645 Computer Science Fall 2018 AP Carnegie Mellon Univ. 2 ADMINISTRIVIA Project #3 is due Monday October 19th Project #4 is due Monday December 10th Homework #4 is due Monday November 12th CMU 15-445/645 (Fall 2018) 3 UPCOMING DATABASE EVENTS BlazingDB Tech Talk → Thursday October 25th @ 12pm → CIC - 4th floor (ISTC Panther Hollow Room) Brytlyt Tech Talk → Thursday November 1st @ 12pm → CIC - 4th floor (ISTC Panther Hollow Room) CMU 15-445/645 (Fall 2018) 4 OBSERVATION Until now, we have assumed that all of the logic for an application is located in the application itself. The application has a "conversation" with the DBMS to store/retrieve data. → Protocols: JDBC, ODBC CMU 15-445/645 (Fall 2018) 5 CONVERSATIONAL DATABASE API Application Parser Planner Optimizer BEGIN Query Execution SQL Program Logic SQL Program Logic ⋮ COMMIT CMU 15-445/645 (Fall 2018) 5 CONVERSATIONAL DATABASE API Application Parser Planner Optimizer BEGIN Query Execution SQL Program Logic SQL Program Logic ⋮ COMMIT CMU 15-445/645 (Fall 2018) 5 CONVERSATIONAL DATABASE API Application Parser Planner Optimizer BEGIN Query Execution SQL Program Logic SQL Program Logic ⋮ COMMIT CMU 15-445/645 (Fall 2018) 5 CONVERSATIONAL DATABASE API Application Parser Planner Optimizer BEGIN Query Execution SQL Program Logic SQL Program Logic ⋮ COMMIT CMU 15-445/645 (Fall 2018) 5 CONVERSATIONAL DATABASE API Application Parser Planner Optimizer BEGIN Query Execution SQL Program Logic SQL Program Logic ⋮ COMMIT CMU 15-445/645 (Fall 2018) 6 EMBEDDED DATABASE LOGIC Move application logic into the DBMS to avoid multiple network round-trips.
    [Show full text]
  • Data Definition Language
    1 Structured Query Language SQL, or Structured Query Language is the most popular declarative language used to work with Relational Databases. Originally developed at IBM, it has been subsequently standard- ized by various standards bodies (ANSI, ISO), and extended by various corporations adding their own features (T-SQL, PL/SQL, etc.). There are two primary parts to SQL: The DDL and DML (& DCL). 2 DDL - Data Definition Language DDL is a standard subset of SQL that is used to define tables (database structure), and other metadata related things. The few basic commands include: CREATE DATABASE, CREATE TABLE, DROP TABLE, and ALTER TABLE. There are many other statements, but those are the ones most commonly used. 2.1 CREATE DATABASE Many database servers allow for the presence of many databases1. In order to create a database, a relatively standard command ‘CREATE DATABASE’ is used. The general format of the command is: CREATE DATABASE <database-name> ; The name can be pretty much anything; usually it shouldn’t have spaces (or those spaces have to be properly escaped). Some databases allow hyphens, and/or underscores in the name. The name is usually limited in size (some databases limit the name to 8 characters, others to 32—in other words, it depends on what database you use). 2.2 DROP DATABASE Just like there is a ‘create database’ there is also a ‘drop database’, which simply removes the database. Note that it doesn’t ask you for confirmation, and once you remove a database, it is gone forever2. DROP DATABASE <database-name> ; 2.3 CREATE TABLE Probably the most common DDL statement is ‘CREATE TABLE’.
    [Show full text]
  • Sqlite Database Schema Table
    Sqlite Database Schema Table Bartholemy is improvably stay-at-home after vicarial Price irrigated his chokies unconquerably. Drawn Patty freeze-drying some etching after squirearchical Jed concentrate overleaf. Snappier and stretching Milt supplant her recti caterwauls while Drew bestraddles some trumpeters telepathically. On the left view that has a field titled Column. Contains a database tables have learned c programming language which contains information than one side go up his financial records contain a query to insert. There heard a few options when it starts. Instead of defining database tables in SQL you write Django models in Python. An object to be converted: a character vectorfor strptime, an object which can be converted to POSIXlt for strftime. Each database before, all tables matching row in a new record header value will be read and close last. Tables can be newly created appended to or overwritten. Close the terminal and open it again. Did you find this article helpful? Tree cells may be distributed throughout the fine content beautiful and but be interspersed with blocks of unused space. Because each record contains facts about a product, as well as facts about a supplier, you cannot delete one without deleting the other. For example, order you currently keep my customer being on index cards. Each schema and saving them, update an alias of table schema. Determining the relationships between tables helps you rather that field have paid right tables and columns. These tables schema table doctors table in sqlite was build with linkedin xray search. Some modification to the definition of equivalent databases perhaps.
    [Show full text]
  • SQL Vs Nosql: a Performance Comparison
    SQL vs NoSQL: A Performance Comparison Ruihan Wang Zongyan Yang University of Rochester University of Rochester [email protected] [email protected] Abstract 2. ACID Properties and CAP Theorem We always hear some statements like ‘SQL is outdated’, 2.1. ACID Properties ‘This is the world of NoSQL’, ‘SQL is still used a lot by We need to refer the ACID properties[12]: most of companies.’ Which one is accurate? Has NoSQL completely replace SQL? Or is NoSQL just a hype? SQL Atomicity (Structured Query Language) is a standard query language A transaction is an atomic unit of processing; it should for relational database management system. The most popu- either be performed in its entirety or not performed at lar types of RDBMS(Relational Database Management Sys- all. tems) like Oracle, MySQL, SQL Server, uses SQL as their Consistency preservation standard database query language.[3] NoSQL means Not A transaction should be consistency preserving, meaning Only SQL, which is a collection of non-relational data stor- that if it is completely executed from beginning to end age systems. The important character of NoSQL is that it re- without interference from other transactions, it should laxes one or more of the ACID properties for a better perfor- take the database from one consistent state to another. mance in desired fields. Some of the NOSQL databases most Isolation companies using are Cassandra, CouchDB, Hadoop Hbase, A transaction should appear as though it is being exe- MongoDB. In this paper, we’ll outline the general differences cuted in iso- lation from other transactions, even though between the SQL and NoSQL, discuss if Relational Database many transactions are execut- ing concurrently.
    [Show full text]
  • Understanding Code Forking in Open Source Software
    EKONOMI OCH SAMHÄLLE ECONOMICS AND SOCIETY LINUS NYMAN – UNDERSTANDING CODE FORKING IN OPEN SOURCE SOFTWARE SOURCE OPEN IN FORKING CODE UNDERSTANDING – NYMAN LINUS UNDERSTANDING CODE FORKING IN OPEN SOURCE SOFTWARE AN EXAMINATION OF CODE FORKING, ITS EFFECT ON OPEN SOURCE SOFTWARE, AND HOW IT IS VIEWED AND PRACTICED BY DEVELOPERS LINUS NYMAN Ekonomi och samhälle Economics and Society Skrifter utgivna vid Svenska handelshögskolan Publications of the Hanken School of Economics Nr 287 Linus Nyman Understanding Code Forking in Open Source Software An examination of code forking, its effect on open source software, and how it is viewed and practiced by developers Helsinki 2015 < Understanding Code Forking in Open Source Software: An examination of code forking, its effect on open source software, and how it is viewed and practiced by developers Key words: Code forking, fork, open source software, free software © Hanken School of Economics & Linus Nyman, 2015 Linus Nyman Hanken School of Economics Information Systems Science, Department of Management and Organisation P.O.Box 479, 00101 Helsinki, Finland Hanken School of Economics ISBN 978-952-232-274-6 (printed) ISBN 978-952-232-275-3 (PDF) ISSN-L 0424-7256 ISSN 0424-7256 (printed) ISSN 2242-699X (PDF) Edita Prima Ltd, Helsinki 2015 i ACKNOWLEDGEMENTS There are many people who either helped make this book possible, or at the very least much more enjoyable to write. Firstly I would like to thank my pre-examiners Imed Hammouda and Björn Lundell for their insightful suggestions and remarks. Furthermore, I am grateful to Imed for also serving as my opponent. I would also like to express my sincere gratitude to Liikesivistysrahasto, the Hanken Foundation, the Wallenberg Foundation, and the Finnish Unix User Group.
    [Show full text]
  • Applying the ETL Process to Blockchain Data. Prospect and Findings
    information Article Applying the ETL Process to Blockchain Data. Prospect and Findings Roberta Galici 1, Laura Ordile 1, Michele Marchesi 1 , Andrea Pinna 2,* and Roberto Tonelli 1 1 Department of Mathematics and Computer Science, University of Cagliari, Via Ospedale 72, 09124 Cagliari, Italy; [email protected] (R.G.); [email protected] (L.O.); [email protected] (M.M.); [email protected] (R.T.) 2 Department of Electrical and Electronic Engineering (DIEE), University of Cagliari, Piazza D’Armi, 09100 Cagliari, Italy * Correspondence: [email protected] Received: 7 March 2020; Accepted: 7 April 2020; Published: 10 April 2020 Abstract: We present a novel strategy, based on the Extract, Transform and Load (ETL) process, to collect data from a blockchain, elaborate and make it available for further analysis. The study aims to satisfy the need for increasingly efficient data extraction strategies and effective representation methods for blockchain data. For this reason, we conceived a system to make scalable the process of blockchain data extraction and clustering, and to provide a SQL database which preserves the distinction between transaction and addresses. The proposed system satisfies the need to cluster addresses in entities, and the need to store the extracted data in a conventional database, making possible the data analysis by querying the database. In general, ETL processes allow the automation of the operation of data selection, data collection and data conditioning from a data warehouse, and produce output data in the best format for subsequent processing or for business. We focus on the Bitcoin blockchain transactions, which we organized in a relational database to distinguish between the input section and the output section of each transaction.
    [Show full text]
  • Application of Sqlite Database in Dispatch and Substation Integrated System
    Advances in Engineering Research, volume 139 2nd International Conference on Electrical Engineering and Automation (ICEEA 2018) Application of SQLite Database in Dispatch and Substation Integrated System Haoqiu Shi*, Xuechun Ji and Hao Li Nari Group Corporation/State Grid Electric Power Research Institute, Nanjing, China *Corresponding author Abstract—Substation monitoring and control system database server and client run in the same process, which can generally consists of several unsupervised PC units. Such reduce the consumption of network access, and can simplify configuration is not suitable for running large commercial database management, while SQLite also supports transaction database, so the integration of dispatching system and processing. The advantages of SQLite in substation systems are transformer substation requires a lightweight relational database, as follows: and has a strict need for the stability and reliability of data. Taking features of SQLite and system requirements into • Zero-configuration. consideration, the paper introduces the SQLite service currently used at substations, and also describes its components and key • Disk-based storage for easy use. mechanism. • SQLite supports Windows, Linux and commercial Keywords—SQLite; lightweight; distributed service; dispatch Unix systems such as Solaris, HPUX, and AIX, while and substation integrated system its data files can be used across platforms. • Database file size up to 2TB. I. INTRODUCTION • Faster than some popular database in most ordinary In accordance with the general strategic plan of SGCC’s database operation. intelligent substation construction, 6100 intelligent substations will be built during the Twelfth Five-Year period. By using the • Provides a simple, easy API for users to use; supports integrated information platform which connects to all key C/C + +.
    [Show full text]