It - SQL Queries
It - SQL Queries
Create statement is used for creating a database or a table in any RDBMS Software.
INSERT statement:
Example:
1) insert into
DOCTOR("ID","NAME","DESIGNATION","ADDRESS","PHONE_NUMBER","SALARY")
VALUES('111','MANJUNATH','PEDIATRICIAN','VIJAYANAGAR','12345567','200000')
OR
Insert into DOCTOR
VALUES('111','MANJUNATH','PEDIATRICIAN','VIJAYANAGAR','12345567','200000')
*Note that all the column name should be specified with double inverted quotes(“)
and values with single inverted quotes(‘).
Example:
1) SELECT * FROM DOCTOR;
[the above command will retrieve all the records from the table,* represents ALL]
OR
select NAME from DOCTOR where DESIGNATION='PEDIATRICIAN' and
ADDRESS='vijayanagar';(this command will not work because of lower case of
'vijayanagar'
7) SELECT “ID” * 2 FROM DOCTOR(it works with double quote and also without “ “)
DISTINCT
The SELECT DISTINCT command returns only distinct (different) values in the result set.
DELETE statement
Delete Statement is used to remove one or more records in a database.
EXAMPLES :
[The above command deletes the record or tuple from the table doctor where doctor ID =121]
[The above command delete the record from doctor table if name is padma and designation of
the doctor is dentist]
[In the above command if we omit where clause all the records will be deleted, but
structure remains the same.]
Update statement
Update statement is used for modifying records in a database.
EXAMPLE:
1) update SDetails
set Location = ‘Bhubaneswar’
where Rollno = 14
OR
2) update SDetails set Location = ‘Bhubaneswar’ where Rollno = ‘14’
Note: Be careful when updating records in a table! Notice the WHERE clause in the UPDATE statement. The
WHERE clause specifies which record(s) that should be updated. If you omit the WHERE clause, all records in
the table will be updated!
ALTER statement
The ALTER TABLE command also adds and deletes various constraints in a table.
Example
ALTER TABLE DOCTOR
ADD REPORTING varchar(225);
TO DROP A COLUMN
The following SQL deletes the "Email" column from the "DOCTOR" table:
ALTER COLUMN command is used to change the data type of a column in a table.
The following SQL COMMAND changes the data type of the column named
"BirthDate" in the"Employees" table to type year:
ALTER TABLE doctor
ALTER COLUMN PHONE_NUMBER VARCHAR(255)
Drop command
The DROP TABLE command deletes a table in the database.
SYNTAX
drop table Tablename
EXAMPLE
drop table doctor;
DROP DATABASE
Example
DROP DATABASE testDB;
DROP COLUMN
The following SQL deletes the "phonenumber" column from the "doctor" table:
Example
ALTER TABLE doctor
DROP COLUMN phonenumber;
EXAMPLE 2
NAME VARCHAR(50),
MARKS NUMERIC(10),
ADDRESS VARCHAR(10),
AGE NUMERIC(10))
2) SELECT *FROM STUDENT
INSERT INTO
STUDENT("ID","NAME","MARKS","ADDRESS","AGE")
VALUES('004','FATHIMA','60','MYSORE','14')
INSERT INTO
STUDENT("ID","NAME","MARKS","ADDRESS","AGE")
VALUES('005','RAMYA','70','MYSORE','17')