Featured Post

What is the purpose of the php.ini file?

  The PHP configuration file,   php.ini , is the final and most immediate way to affect PHP's functionality. The php.ini file is read ea...

Why do we use SQL constraints? Which constraints we can use while creating a database in SQL?

 Constraints are used to set the rules for all records in the table. If any constraints get violated then it can abort the action that caused it.

Constraints are defined while creating the database itself with the CREATE TABLE statement or even after the table is created once with the ALTER TABLE statement.

There are 5 major constraints are used in SQL, such as

  • NOT NULL: That indicates that the column must have some value and cannot be left NULL.
  • UNIQUE: This constraint is used to ensure that each row and column has a unique value and no value is being repeated in any other row or column.
  • PRIMARY KEY: This constraint is used in association with NOT NULL and UNIQUE constraints such as on one or the combination of more than one column to identify the particular record with a unique identity.
  • FOREIGN KEY: It is used to ensure the referential integrity of data in the table. It matches the value in one table with another using the PRIMARY KEY.
  • CHECK: It ensures whether the value in columns fulfills the specified condition.

What are different Clauses used in SQL?

 WHERE Clause: This clause is used to define the condition, extract and display only those records which fulfill the given condition.

Syntax:

SELECT column_name(s) 
 FROM table_name 
 WHERE condition;

GROUP BY Clause: It is used with SELECT statement to group the result of the executed query using the value specified in it. It matches the value with the column name in tables and groups the end result accordingly.

Syntax:

SELECT column_name(s)
 FROM table_name
 GROUP BY column_name;

HAVING clause: This clause is used in association with the GROUP BY clause. It is applied to each group of results or the entire result as a single group. It is much similar as WHERE clause but the only difference is you cannot use it without GROUP BY clause

Syntax:

 
SELECT column_name(s) 
 FROM table_name 
 GROUP BY column_name 
 HAVING condition;

ORDER BY clause: This clause is used to define the order of the query output either in ascending (ASC) or in descending (DESC). Ascending (ASC) is set as the default one but descending (DESC) is set explicitly.

Syntax:

SELECT column_name(s) 
 FROM table_name 
 WHERE condition 
 ORDER BY column_name ASC|DESC;

USING clause: USING clause comes in use while working with SQL JOIN. It is used to check equality based on columns when tables are joined. It can be used instead of the ON clause in JOIN.

Syntax:

SELECT column_name(s) 
 FROM table_name 
 JOIN table_name 
 USING (column_name);

What are the different types of statements supported by SQL?

There are 3 types of SQL statements:

a) DDL (Data Definition Language): It is used to define the database structure such as tables. It includes three statements such as CREATE, ALTER, and DROP.

Also read =>> MySQL Create Table Tutorial

Some of the DDL Commands are listed below:

CREATE: It is used for creating the table.

CREATE TABLE table_name
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size),

ALTER: The ALTER table is used for modifying the existing table object in the database.

ALTER TABLE table_name
 ADD column_name datatype

OR

ALTER TABLE table_name
DROP COLUMN column_name

b) DML (Data Manipulation Language): These statements are used to manipulate the data in records. Commonly used DML statements are INSERT, UPDATE, and DELETE.

The SELECT statement is used as a partial DML statement, used to select all or relevant records in the table.

c) DCL (Data Control Language): These statements are used to set privileges such as GRANT and REVOKE database access permission to the specific user.

How do we use the DISTINCT statement? What is its use?

The DISTINCT statement is used with the SELECT statement. If the record contains duplicate values then the DISTINCT statement is used to select different values among duplicate records.

Syntax:

SELECT DISTINCT <column_name(s)> FROM <table_name>;

What is SQL?

 Structured Query Language SQL is a database tool that is used to create and access the database to support software applications.

What is the use of “echo” in php?

 It is used to print a data in the webpage, Example: , The following code print the text in the webpage

Is PHP a strongly typed language?

No. PHP is a weakly typed or loosely typed language.

This means PHP does not require to declare data types of the variable when you declare any variable like the other standard programming languages C# or Java. When you store any string value in a variable, then the data type is the string and if you store a numeric value in that same variable then the data type is an Integer.

Sample code:

$var = "Hello"; //String
$var = 10; //Integer

Why do we use PHP?

 There are several benefits of using PHP. First of all, it is totally free to use. So anyone can use PHP without any cost and host the site at a minimal cost.

It supports multiple databases. The most commonly used database is MySQL which is also free to use. Many PHP frameworks are used now for web development, such as CodeIgniter, CakePHP, Laravel, etc.

These frameworks make the web development task much easier than before.

What is SQL?

 Structured Query Language SQL is a database tool that is used to create and access the database to support software applications.

What are tables in SQL?

 The table is a collection of record and its information at a single view.

What are tables in SQL?

 The table is a collection of record and its information at a single view.

What is the purpose of using the TIMESTAMP data type?

 A TIMESTAMP data type is used to store the combination of date and time value which is 19 characters long.

The format of TIMESTAMP is YYYY-MM-DD HH:MM: SS. It can store data from ‘1970-01-01 00:00:01’ UTC to ‘2038-01-19 03:14:07’ UTC. By default, the current date and time of the server get inserted in the field of this data type when a new record is inserted or updated.

How can you find out the version of the installed MySQL?

 The version of the installed MySQL server can be found out easily by running the following command from the MySQL prompt.

mysql> SHOW VARIABLES LIKE “%version%”;

Popular Posts