what is SQL?
basically sql stands for sturctured query language is a database management language relational database.
sql isn`t a programming language ,its a query language.
some common relational database management system that use sql are : Oracle , sybase ,microsoft sql server etc.
The standard sql commands such as "select","Insert","Update"," Delete","Create","Drop" can be used to accomplish almost everything that one needs to do with a database.
Every table is divided into smaller entities called fields. The fields in the Customers table consist of CustomerID, CustomerName, ContactName, Address, City, PostalCode and Country. A field is a column in a table that is designed to maintain specific information about every record in the table.
A record, also called a row, is each individual entry that exists in a table. For example, there are 91 records in the above Customers table. A record is a horizontal entity in a table.
Uses of SQL:-
- SQL is used to communicate with a databse.
- sql statements are used to performs tasks such as update data on a database.
- Retrieve data from a database .
- SQL lets you access and manipulate database.
- sql can create views in a database.
- sql can set permission on tables procedures and users.
Data Definition language (DDL):- :-
Data manipulation language(DML):-
The SQL-DML includes those commands , which are based on both the relational algebra and the tuple relational calculus . DML is a language that enales users to access or manipulate data. By data manipulation ,we mean:
- The retrieval of information stored in the table .
- The insertion of new rows with information into the table.
- The modification of information stored into the table.
- DCL:- Data control language.
- TCL:- Trasaction control language.
Data types :-
1.DECIMAL and NUMERIC :-
Fixed precision and decimal numbers ,DECIMAL and NUMERIC are functionally equivalent .
syntax:
DECIMAL ( precision [ , scale ] )
NUMERIC ( precision [ , scale ] )
examples:-
SELECT CAST ( 123 AS DECIMAL (5,2 ) ) - - returns 123.00
SELECT CAST ( 12345.12 AS NUMERIC ( 10,5 0) - - returns 3 . 141593
2. FLOAT and REAL:-
Approximate number datatypes for use with floating point numeric data.
SELECT CAST ( (PI ( ) AS FLOAT ) --return 3.14159265358979
SELECT CAST ( ( PI ( ) AS REAL ) -- returns 3.141593
3. INTEGERS:-
Exact number data types that use integer data.
Data type Range Storage
bigint -2^63 (-9,223,372,036,854,775,808) to
2^63-1 (9,223,372,036,854,775,807) 8bytes
int -2^31 (-2,147,483,648) to 2^31-1
(2,147,483,647) 4bytes
smallint -2^15 (-32,768) to 2^15-1 (32,767) 2bytes
tinyint 0 to 255 1bytes
4. MONEY and SMALLMONEY :-
Datatypes that represent monetary and currency value.
Data type Range Storage
money -922,337,203,685,4775808 to
922337,203,685,477,5807 8bytes
smallmoney -214,748.3648 to 214,748.3648 4bytes
5 .BINARY and VARBINARY:-
Binary datatype either fixed length or variable length.
Syntax:-
BINARY [ ( n_bytes) ]
VARBINARY [ ( n_bytes | max ) ]
n_bytes can be any number fro 1 to 8000 bytes. max indicates that the max storage space is 2^31-1.
examples:-
SELECT CAST (12345 AS BINARY( 10 ) ) -- 0X000000000000000000003039
SELECT CAST ( 12345 AS VARBINARY ( 10 ) ) - - 0X00003039
6.CHAR and VARCHAR:-
String datatypes of either fixed lenght or variable lenght.
syntax:-
CHAR [ ( n_chars ) ]
VARCHAR [ ( n_chars ) ]
7.NCHAR and NVARCHAR:-
UNICODE String datatypes of either fixed lenght or variable lenght.
syntax :
NCHAR [ ( n_chars ) ]
NVARCHAR [ ( n_chars | MAX ) ]
use MAX for very long string that may exceed 8000 characters .
Some of The Most Important SQL Commands:-
- SELECT - extracts data from a database
- UPDATE - updates data in a database
- DELETE - deletes data from a database
- INSERT INTO - inserts new data into a database
- CREATE DATABASE - creates a new database
- ALTER DATABASE - modifies a database
- CREATE TABLE - creates a new table
- ALTER TABLE - modifies a table
- DROP TABLE - deletes a table
- CREATE INDEX - creates an index (search key)
- DROP INDEX - deletes an index
Statements of SQL:-
Mostly the actions are perform on a database are done with SQL statements.
so the following SQL statement selects all the records in the "Customers" table:
Example
SELECT * FROM Customers;Remember That...
- SQL keywords are NOT case sensitive: select is the same as SELECT
Semicolon after the SQL Statements:--
Some database systems need a semicolon at the end of each SQL statement.
Semicolon is the standard way to separate each SQL statement in database systems that allow more than one SQL statement to be executed in the same call to the server.
No comments:
Post a Comment
learnerspoint0826@gmail.com