DBMS and SQL
A Database Management System (DBMS), is a software program that enables the users to access database, manipulate data and represent it. SQL (Structured Query Language) is one of the RDBMS examples. SQL divides its commands on the basis of functionalities performed by them
The main types of commands in SQL are:
DDL (Data Definition Language) – DDL manages table and index structure. The most basic commands of DDL are create, alter, rename and drop statements.
Create – create an object in the database.
CREATE TABLE table_name (
Drop – delete an object (table) in the database.
DROP TABLE table_name;
Alter – modify the structure of an existing object in the database.
ALTER TABLE table_name
ADD column_name datatype;
- Create – create an object in the database.
DML (Data Manipulation Language) – DML is a subset of SQL used to add, update, and delete the data. They are the queries that modify data. The most basic commands of DML are Insert, Select, Update, Delete.
Insert statement is used to insert data into an existing table. The Insert
statement has the following format
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3, ...);
The SELECT statement is used for retrieving the data stored in a single table or in multiple related tables. Select has three main keywords: SELECT, FROM and WHERE. The SELECT list is the list of columns (from one or multiple tables) or computed values that are to be retrieved from the query. The FROM statement specifies the table, tables, or views from which you want to fetch the data. The WHERE clause specifies a condition to include or exclude rows for the query’s output.
SELECT column1, column2,
Here, column1 and column2 are the field names of the table from where you want to select data. If you want to select all the fields which are available in the table, use the following syntax:
SELECT * FROM table_name;
The update statement is used to modify the table data.
SET column1 = value1, column2 = value2, ...
The delete statement is used to remove records permanently from a table.
DELETE FROM table_name WHERE condition;
The truncate statement removes all records from a table. It executes faster than a DELETE statement without a WHERE clause. TRUNCATE statement retains the structure of the table. It will also reinitialize the identity columns to the specified initial value. It looks like this:
TRUNCATE TABLE table_name;
- INSERT –
Constraints In SQL-
Constraints are the conditions used to limit or control the type or values of data that the user can enter into the tables. The main categories of constraints are:-
- Primary key constraints.
- Foreign key constraints.
- Default constraints.
- Not null constraints.
- Check constraints.
- Unique constraints.
- Primary key constraints:-
A Primary key constraint is a column or a set of columns that uniquely identify a row in the table. Although you can assign more than one field as the primary key, each table can have only one primary key. A primary key column value must be unique and not null.
- Foreign key constraints:-
A foreign key constraint consists of a column or a set of columns that is related to column/s of a primary key table. It can be one to one or one to many relationships. The primary key is on one side of the relationship, whereas the foreign key is on the many sides of the relationship. It is possible to have multiple foreign keys in a table. Each foreign key relates to a primary key in another table. While adding records in a table with a foreign key, the value must be present in the related table with a primary key.
- Default constraints:-
A default constraint is a default value that SQL Server automatically places in a particular field in a table. A default value can be constant, NULL, or a function. All fields except identity and time stamp fields can contain default values. Each column can have one default constraint.
- Not Null Constraints:-
In certain situations, data in a field is required for example a father’s name is compulsory. The Not Null constraint enables you to accomplish this task.
- Check Constraints:-
Check constraints can be used to limit the range of values that a user can enter into a column. Multiple Check constraints are allowed for a particular column.
- Unique Constraints:-
A unique constraint requires that each entry in a particular column is unique. A unique constraint is created by creating a unique index. The UNIQUE constraint identifies each record in a database table. The difference between UNIQUE constraint and PRIMARY Key is that unique columns can contain null whereas the primary key column is not null. There can be only one primary key in a table but multiple unique keys are allowed in the table.
PHP programming is a valuable skill that a programmer can have. Let StudySection help you out with proving your programming skills through its PHP certification. StudySection provides beginner as well as expert-level certifications in PHP programming to prove your level of skills in PHP programming.