Prabu's sql quries


Published on

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Prabu's sql quries

  2. 2. CREATING TABLE The SQL syntax for CREATE TABLE is CREATE TABLE "table_name" ("column 1" "data_type_for_column_1", "column 2" "data_type_for_column_2", ... )
  3. 3. ALTER TABLE <ul><li>This ALTER TABLE sql command is to make changes in the table.
  4. 4. The synatx is: </li></ul>ALTER TABLE[ owner_name ] table_name [ADD column_name datatype attributes] [MODIFY{column_name datatype | column_constraint}] <ul><li>Example Query: </li></ul>ALTER TABLE STUDENT ADD(PERCENTAGE NUMBER(5,2));
  5. 5. INSERT The SQL INSERT INTO clause facilitates the process of inserting data into a SQL table. Here is how you can insert a new row into the Weather table, using SQL INSERT INTO: Insert into tablename ( fieldname, fieldname, fieldname ) values ( value, value, value );
  6. 6. SELECT The SQL SELECT clause selects data from one or more database tables and/or views. In its basic form the SQL SELECT syntax looks like this: SELECT ColumnName1, ColumnName2, … FROM Table1
  7. 7. WHERE The SQL WHERE clause works in conjunction with other SQL clauses like SELECT, INSERT and UPDATE to specify a search condition for these statements. We are going to give an example of the SQL WHERE clause used along with the SQL SELECT clause: SELECT AverageTemperature FROM Weather WHERE City = 'New York'
  8. 8. DISTINCT The SQL DISTINCT clause works in conjunction with the SQL SELECT clause and selects only distinct (unique) data from a database table(s). Here is an example of SQL DISTINCT clause SELECT DISTINCT Column1 FROM Table1
  9. 9. UPDATE The SQL UPDATE clause serves to update data in database table. The SQL UPDATE clause basic syntax looks like this: UPDATE Table1 SET Column1 = Value1, Column2 = Value2, …
  10. 10. DELETE The SQL DELETE clause is used to delete data from a database table. The simplest SQL DELETE syntax looks like this: DELETE FROM Table1
  11. 11. TRUNCATE The SQL TRUNCATE TABLE clause deletes all rows from a database table. Here is the SQL TRUNCATE TABLE syntax: TRUNCATE TABLE Weather
  12. 12. ORDER BY The SQL ORDERBY clause defines in what order to return a data set retrieved with a SQL SELECT statement. Here is an example of using SQL ORDER BY to order the rows : Select */fieldname<mask> ... from tablename order by fieldname ;
  13. 13. SQL AVERAGE To get the average temperature for the Weather table use the AVG SQL aggregate function: SELECT AVG(AverageTemperature) FROM Weather
  14. 14. SQL MINIMUM To get the minimum value from a numeric table column, use the SQL MIN aggregate function: SELECT MIN(AverageTemperature) FROM Weather
  15. 15. SQL MAXIMUM To get the maximum value from a numeric table column, use the SQL MAX aggregate function: SELECT MAX(AverageTemperature) FROM Weather
  16. 16. SQL GROUP BY The SQL GROUP BY CITY clause is used along with the SQL aggregate functions and specifies the groups where selected rows are placed. WHEN one or more aggregate functions are presented in the SQL SELECT column list, the SQL GROUP BY clause calculates a summary value for each group EX:Our task is to calculate the average temperature for each of the cities in the Weather table. Here is how to accomplish that using the SQL GROUP BY clause: SELECT City, AVG(AverageTemperature) FROM Weather GROUP BY City
  17. 17. SQL JOIN The SQL JOIN clause selects data from two or more tables tied together by matching table columns SELECT Weather.City, Weather.AverageTemperature, Weather.Date, State.State FROM Weather JOIN State ON Weather.City = State.City
  18. 18. AND/OR The Syntax for AND/OR SELECT &quot;column_name&quot; FROM &quot;table_name&quot; WHERE &quot;simple condition&quot; {[AND|OR] &quot;simple condition&quot;}+
  19. 19. IN The Syntax for IN statement in SQL is SELECT &quot;column_name&quot; FROM &quot;table_name&quot; WHERE &quot;column_name&quot; IN ('value1', 'value2', ...)
  20. 20. BETWEEN The Syntax for BETWEEN statement in SQL is SELECT &quot;column_name&quot; FROM &quot;table_name&quot; WHERE &quot;column_name&quot; BETWEEN 'value1' AND 'value2'
  21. 21. DROP The Syntax for DROP statement in SQL is DROP TABLE &quot;table_name&quot;