What is the command for SQL...?




What is the command for SQL 

Structured Query Language is instruction, it is used to communicate to database how to use and how will be monitored & manage them to SQL following are comm-and for SQL (Structured query language).

Some Of The Most Important SQL Commands

CREATE DATABASE – creates a new database.
      Create database databasename;
CREATE TABLE – create a new table

     CREATE TABLE table_name
     (                                     
     column_name1 data_type(size),
    column_name2 data_type(size)’
   column_name3 data type(size),
 
  );

The column_name parameters specify the names of the columns of the table. 
The data type parameter specifies what type of data the column can hold (e.g. varchar, integer, decimal, date, etc.).
The size parameter specifies the maximum length of the column of the table.

Example:     


CREATE TABLE suppliers
(supplier_id number(10) NOT NULL,
 Supplier_name varchar 2(50) NOT NULL, 

 contact_name varchar2(50);   

The ALTER TABLE Statement      
The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.

SQL ALTER TABLE Syntax  
To add the column: To add a column in a table, use the following syntax:

ALTER TABLE table_name
DROP COLUMN column_name

Example:

ADD (supplier_name vaechar2(50),
     City varchar2(45);

To delete the column:  To delete a column in a table, use the following syntax (notice that some database systems don’t allow deleting a column):

ALTER TABLE table_name
DROP COLUMN column_name

Example:
ALTER TABLE supplier
 DROP COLUMN supplier_name;

To modify the column: To change the data type of a column in table, use the following syntax:

SQL Server / MS Access :

ALTER TABLE table_name
ALTER COLUMN column_name datatype

My SQL/ Oracle (prior version 10G)
ALTER TABLE table_name
MODIFY COLUMN column_name datatype

Example:
 ALTER TABLE supplier
MODIFY supplier_name varchar2(100) not null;

Oracle 10G and later:
ALTER                            TABLE                             table_name
MODIFY column_name datatype

Rename column in table
Syntax

To rename a column in an existing table; the SQL ALTER TABES syntax is:
ALTER TABLE table_name
 RENAME COLUMN old_name to new_name;

For example:
ALTER TABLE supplier
      RENAME COLUMN supplier_name to sname;

The DROP TABLE Statement
The DROP TABLE statement is use to delete a table.
Drop table tablename;

The DROP DATABASE Statement
The DROP DATABASE statement is used to delete a  database.
DROP DATABASE database_name

The TRUNCATE TABLE Statement
What if we only want to delete the data inside the table, and not the table itself?
Then, use the TRUNCATE TABLE statement:
TRUNCATE TABLE table_name

The SQL INSERT INTO Statement
The INSERT INTO statement is used to insert new records in a table.

SQL INSERT INTO Syntax
It is possible to write the INSERT INTO statement in two forms.
The first form does not specify the column names where the date will data will be inserted, only their values:
INSERT INTO table_name
VALUES (value1,value2,value3,...);

Example:
INSERT INTO sup;iers
(supplier_id, supplier_name)
VALUES
(24553,’IBM’);

The SQL SELECT Statement
The SELECT statement is used to select data from a database.
The result is stored  in a result table, called the result-set.

SQL SELECT Syntax
SELECT column _name, column_name
FROM table_name
And
SELECT* FROM table_name;

Example:
SELECT supplier_name,city,state
FROM supplier

The  SQL WHARE Clause
The WHERE clause is used to extract only those records  the fulfill a specified criterion.

SQL WHERE Syntax

SELECT column_name,column_name
FROM table_name
WHERE column_name operator value;


Operators in The WHERE Clause
The WHERE clause is used in the WHERE clause:


Operator
Description
=
Equal
<> 
Not equal. Note: In some version of SQL this operator may be written as ! =
> 
Greater than
< 
Less than
>=
Greater than or equal
<=
Less than or equal
BETWEEM
Between an inclusive range
LIKE
Search for a pattern
IN
To specify multiple possible values for a column               

 The SQL AND & OR Operators

The AND operator displays a record if both first condition AND the second condition are true.
The OR operator displays a records if either the first condition OR the second condition is true.

SELECT ID, NAME, SALARY
FROM CUSTOMERS
WHERE SALARY > 2000 AND age < 25;

Following is an example, which would fetch  ID, Name and Salary fields from the CUSTOMERS table where salary is greater than 2000 AND age is less than 25 years.     

SELECT ID, NAME, SALARY
FROM CUSTOMERS
WHERE SALARY > 2000 OR   age < 25;

Following is an example, which would fetch ID, Name and Salary field the CUSTOMERS table where salary is greater than 2000 OR age is less than 25 years.

SQL LIKE Operator:
The LIKE operator  is used in a WHERE clause to search for a specified pattern in a column.

SELECT COLUMN_name(s)
FROM table_name
WHERE column_name LIKE  pattern                                                                        

Post a Comment

0 Comments