SQL Commands Notes
SQL Commands Notes
Syntax:
Example:
b. DROP: It is used to delete both the structure and record stored in the table.
Example
c. ALTER: It is used to alter the structure of the database. This change could be either
to modify the characteristics of an existing attribute or probably to add a new
attribute.
Following are the list of modifications that can be done using ALTER command.
o With the use of ALTER commands we can add or drop one or more columns
form existing tables.
o Increase or decrease the existing column width by changing the data type
o Make an existing mandatory column to optional.
o Enable or disable the integrity constraints in a table. We can also add, modify
or delete the integrity constraints from a table.
o We can also specify a default value for existing column in a table.
With the use of ALTER table command we can add new columns existing table.
EXAMPLE:
Example:
With the use of ALTER table we can modify column and constraint in the existing
table. These statements can increase or decrease the column widths and changing a
column from mandatory to optional.
Syntax:
Example:
Example:
ADVERTISEMENT
ADVERTISEMENT
Example:
RENAMING TABLE
SQL provides the facility to change the name of the table by using a ALTER TABLE
statement.
Syntax:
Example:
d. TRUNCATE: It is used to delete all the rows from the table and free the space
containing the table.
Syntax:
Example:
1. TRUNCATE TABLE EMPLOYEE;
Syntax:
a. INSERT: The INSERT statement is a SQL query. It is used to insert data into the row
of a table. To insert a new row into a table you must be your on schema or INSERT
privilege on the table.
Following are the list of points should be considered while inserting the data
into tables.
o SQL uses all the columns by default if you do not specify the column name
while inserting a row.
o The number of columns in the list of column name must match the number of
values that appear in parenthesis after the word "values".
o The data type for a column and its corresponding value must match.
or
For example:
1. INSERT INTO javatpoint (Author, Subject) VALUES ("Sonoo", "DBMS"), ("Raman", "DB
MS"), ("Priya", "DBMS");
b. UPDATE: This command is used to update or modify the value of a column in the
table.
In the above syntax, table_name is the name of the table, the column_name is the
name of column in the table to be modified, and value1 corresponds to the valid SQL
values. The "WHERE" is a condition that restricts the rows updated for which the
specified condition is true. If condition is not specified is not defined then SQL
updates all the rows in the table. It contains comparison and logical operators etc.
The following the list of points should be remembered while executing the
UPDATE statement.
1. UPDATE students
2. SET User_Name = 'Sonoo'
3. WHERE Student_Id = '3'
c. DELETE: It is used to remove one or more row from a table. To delete rows from
the table, it must be in your schema or you must have delete privilege.
DQL
Syntax
Syntax
• Inside a table, a column often contains many duplicate values; and sometimes you only want
to list the different (distinct) values.
Where clause
• The where clause is used to filter records.
Syntax
Limit clause
• The limit clause is used to set an upper limit on the number of tuples returned by sql.
Syntax
limit5;
Example
ORDER BY CLAUSE
• The ORDER BY is used to sort the result-set
Example