AIM: Study data types in SQL and usage of various Data Definition Language commands. PROCEDURE: What is SQL? SQL is structured Query Language which is a computer language for storing, manipulating and retrieving data stored in relational database. SQL is the standard language for Relation Database System. All relational database management systems like MySQL, MS Access, Oracle, Sybase, Informix, postgres and SQL Server uses SQL as standard database language. Also they are using different dialects, Such as: • MS SQL Server using T-SQL, • Oracle using PL/SQL, • MS Access version of SQL is called JET SQL (native format )etc Why SQL? • Allow users to access data in relational database management systems. • Allow users to describe the data. • Allow users to define the data in database and manipulate that data. • Allow to embed within other languages using SQL modules, libraries & pre-compilers. • Allow users to create and drop databases and tables. • Allow users to create view, stored procedure, functions in a database. • Allow users to set permissions on tables, procedures, and views History: • 1970 -- Dr. E.F. "Ted" of IBM is known as the father of relational databases. He described a relational model for databases. • 1974 -- Structured Query Language appeared. • 1978 -- IBM worked to develop Codd's ideas and released a product named System/R. • 1986 -- IBM developed the first prototype of relational database and standardized by ANSI. The first relational database was released by Relational Software and its later becoming Oracle.
DATA TYPES: Data Type integer smallint numeric decimal Real double precision Float character character varying Bit bit varying Date Time timestamp time with time zone timestamp with time zone year-month interval day-time interval Syntax Integer Smallint numeric(p,s) decimal(p,s) Real Explanation (if applicable)
Where p is a precision value; s is a scale value. For example, numeric(6,2) is a number that has 4 digits before the decimal and 2 digits after the decimal. Where p is a precision value; s is a scale value. Single-precision floating point number
double precision Double-precision floating point number float(p) char(x) varchar2(x) bit(x) bit varying(x) date time timestamp time with time zone timestamp with time zone Where p is a precision value. Where x is the number of characters to store. This data type is space padded to fill the number of characters specified. Where x is the number of characters to store. This data type does NOT space pad. Where x is the number of bits to store. Where x is the number of bits to store. The length can vary up to x. Stores year, month, and day values. Stores the hour, minute, and second values. Stores year, month, day, hour, minute, and second values. Exactly the same as time, but also stores an offset from UTC of the time specified. Exactly the same as timestamp, but also stores an offset from UTC of the time specified. Contains a year value, a month value, or both. Contains a day value, an hour value, a minute value, and/or a second value.
SQL Commands: SQL commands are instructions used to communicate with the database to perform specific task that work with data. SQL commands can be used not only for searching the database but also to perform various other functions like, for example, you can create tables, add data to tables, or modify data, drop the table, set permissions for users. SQL commands are grouped into four major categories depending on their functionality: •
Data Definition Language (DDL) - These SQL commands are used for creating, modifying, and dropping the structure of database objects. The commands are CREATE, ALTER, DROP, RENAME, and TRUNCATE. Data Manipulation Language (DML) - These SQL commands are used for storing, retrieving, modifying, and deleting data. These commands are INSERT, UPDATE, and DELETE. Transaction Control Language (TCL) - These SQL commands are used for managing...