Hi friends, today I will say you about basic Sql commands that
we use while creating our project.
1) Create
2) Insert
3) Update
4) Delete
Create Table Statement
CREATE TABLE "table_name"
("column 1" "data type for column 1" [column 1 constraint(s)],
"column 2" "data type for column 2" [column 2 constraint(s)],
...
[table constraint(s)]);
("column 1" "data type for column 1" [column 1 constraint(s)],
"column 2" "data type for column 2" [column 2 constraint(s)],
...
[table constraint(s)]);
· Drop Table Statement
DROP TABLE "table_name";
DROP TABLE "table_name";
· Truncate Table Statement
TRUNCATE TABLE "table_name";
TRUNCATE TABLE "table_name";
· Insert Into Statement
INSERT INTO "table_name" ("column1", "column2", ...)
VALUES ("value1", "value2", ...);
INSERT INTO "table_name" ("column1", "column2", ...)
VALUES ("value1", "value2", ...);
· Update Statement
UPDATE "table_name"
SET "column_1" = [new value]
WHERE "condition";
UPDATE "table_name"
SET "column_1" = [new value]
WHERE "condition";
· Delete From Statement
DELETE FROM "table_name"
WHERE "condition";
DELETE FROM "table_name"
WHERE "condition";
· Alter Statement
ALTER TABLE tb_TableName ADD Record_Status varchar(20);
ALTER TABLE tb_TableName
add constraint cnt_Record_Status Default '' for Record_Status;
Six types of constraints can be placed when creating a table:
·
NOT NULL Constraint: Ensures that a column cannot
have NULL value.
·
DEFAULT Constraint: Provides a default value for a
column when none is specified.
·
UNIQUE Constraint: Ensures that all values in a
column are different.
·
CHECK Constraint: Makes sure that all values in a
column satisfy certain criteria.
·
Primary Key Constraint: Used to uniquely identify
a row in the table.
·
Foreign Key Constraint: Used to ensure referential
integrity of the data.
SQL > SQL
Syntax
In this page, I have listed the
SQL syntax for each of the SQL commands in this tutorial, making this an easy
reference for someone to learn SQL.
· Select Statement
SELECT "column_name" FROM "table_name";
·
Distinct
SELECT DISTINCT "column_name"
FROM "table_name";
SELECT DISTINCT "column_name"
FROM "table_name";
·
Where
SELECT "column_name"
FROM "table_name"
WHERE "condition";
SELECT "column_name"
FROM "table_name"
WHERE "condition";
·
And/Or
SELECT "column_name"
FROM "table_name"
WHERE "simple condition"
{[AND|OR] "simple condition"}+;
SELECT "column_name"
FROM "table_name"
WHERE "simple condition"
{[AND|OR] "simple condition"}+;
·
In
SELECT "column_name"
FROM "table_name"
WHERE "column_name" IN ('value1', 'value2', ...);
SELECT "column_name"
FROM "table_name"
WHERE "column_name" IN ('value1', 'value2', ...);
·
Between
SELECT "column_name"
FROM "table_name"
WHERE "column_name" BETWEEN 'value1' AND 'value2';
SELECT "column_name"
FROM "table_name"
WHERE "column_name" BETWEEN 'value1' AND 'value2';
·
Like
SELECT "column_name"
FROM "table_name"
WHERE "column_name" LIKE {PATTERN};
SELECT "column_name"
FROM "table_name"
WHERE "column_name" LIKE {PATTERN};
·
Order By
SELECT "column_name"
FROM "table_name"
[WHERE "condition"]
ORDER BY "column_name" [ASC, DESC];
SELECT "column_name"
FROM "table_name"
[WHERE "condition"]
ORDER BY "column_name" [ASC, DESC];
·
Count
SELECT COUNT("column_name")
FROM "table_name";
SELECT COUNT("column_name")
FROM "table_name";
·
Group By
SELECT "column_name1", SUM("column_name2")
FROM "table_name"
GROUP BY "column_name1";
SELECT "column_name1", SUM("column_name2")
FROM "table_name"
GROUP BY "column_name1";
·
Having
SELECT "column_name1", [Function("column_name2")]
FROM "table_name"
[GROUP BY "column_name1"]
HAVING (arithematic function condition);
SELECT "column_name1", [Function("column_name2")]
FROM "table_name"
[GROUP BY "column_name1"]
HAVING (arithematic function condition);
You can rate my class on right side top of my blog......
-Your's santoshklpkl
·
No comments:
Post a Comment