Firstly, Structured Query Language is for storing and managing data in RDMS i.e. Relational Database System. Moreover, as we have already learnt about Database Management System, we will know more about RDMS and SQL.
In addition, this language enables users to perform four types of operation which are as follows:
- Create
- Read
- Update
- Delete
These are commonly known as CRUD operations.
Structured Query Language DATA TYPES
Let us take a look at some built in data types in SQL:
- int: for declaring integer data types.
- char: for fix length character values.
- varchar(n): for variable length values.
- numeric(p,d): for decimal point values with specific precision.
CREATE COMMAND
Firstly, to create a table, we use the following command:
create table tablename(columnname1 datatype1, columnname2 datatype2,…)
For instance, create table record(id int, name varchar(20))
ALTER COMMAND
Secondly, To add a column in table:
alter table tablename add column columnname datatype;
Thirdly, To change column name, we use alter and change command:
alter table tablename change column existing_columnname new_columnname datatype;
UPDATE COMMAND
Moreover, To update a value, use the command shown below:
update tablename set columnname = value1 where condition;
DELETE COMMAND
To delete a particular row,we use the following command:
delete from tablename where columnname = value;
DROP COMMAND
Certainly, To drop a column:
alter table tablename drop column columnname;
In addition, To drop a table with its definition:
drop table tablename;
SELECT COMMAND
To print data from table, we use select command:
- select * from tablename;
- select column1, column2 from tablename;
Difference between DROP & DELETE command
DROP is a data definition language (DDL) command whereas DELETE is a data manipulation language (DML) command.
Also drop is to delete a table or its column whereas delete command is to remove a particular row.
Instance and Schemas
At a particular moment what data is available is known as instance. Schema is the design of the database.
Schema is of two types: Physical Schema and Logical Schema. Physical schema is represented at physical level. Logical schema is to design at logical level.
Summary
In conclusion, we have learnt that Structured Query Language is for storing and managing data in RDMS i.e. Relational Database System. Moreover, this language enables users to perform four types of operation i.e. CREATE, READ, UPDATE & DELETE (CRUD) Operations.
DROP is a data definition language (DDL) command whereas DELETE is a data manipulation language (DML) command. We have also seen syntax of some more commands like UPDATE, SELECT, CREATE & ALTER.
[…] DML operations on Database are used to create Store Procedures. Secondly, it is a collection of SQL statements which accepts input in form of parameters. Moreover, store procedures may or may not return a […]