





































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A comprehensive overview of sql commands and constraints, essential for database management and manipulation. It covers various commands such as create, drop, insert, select, update, and alter, along with clauses like where, between, is null, and distinct. The document also explains constraints like not null, default, unique, check, primary key, and foreign key, providing syntax and examples for each. It is useful for students and professionals learning or refreshing their knowledge of sql database operations. Examples of creating tables, inserting data, and modifying table structures, making it a practical guide for database management.
Typology: Study notes
1 / 77
This page cannot be seen from the preview
Don't miss anything!






































































C. Date and Time Datatypes - These datatypes stores date and time.
(represents by 1 and 0).
CREATE TABLE Employees ( EmployeeID INT, FirstName VARCHAR(50), LastName CHAR(20), Salary DECIMAL(10, 2), BirthDate DATE, HireTime TIME, IsActive BIT );
CREATE DATABASE database_name;
CREATE DATABASE SalesDB;
in the system.
USE database_name;
USE SalesDB;
CREATE TABLE table_name( column1 datatype, column2 datatype, column3 datatype, ..... columnN datatype, );
INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);
VALUES (1, 'Ramesh', 32, 'Ahmedabad', 2000.00); INSERT INTO CUSTOMERS (ID, NAME, AGE, ADDRESS, SALARY) VALUES (2, 'Khilan', 25, 'Delhi', 1500.00); You can create a record in the CUSTOMERS table by using the second syntax as shown below. NOTE- You may not need to specify the column(s) name in the SQL query if you are adding values for all the columns of the table. But make sure the order of the values is in the same order as the columns in the table.
INSERT INTO table_name VALUES (value1, value2, value3, ...)
INSERT INTO CUSTOMERS VALUES (3, 'Kaushik', 23, 'Kota', 2000.00); INSERT INTO CUSTOMERS VALUES (4, 'Chaitali', 25, 'Mumbai', 6500.00); INSERT INTO CUSTOMERS VALUES (5, 'Hardik', 27, 'Bhopal', 8500.00); INSERT INTO CUSTOMERS VALUES (6, 'Muffy', 24, 'Indore', 10000.00 );
INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);
VALUES (7, 'Bharti', 1 2 000.00 );
SELECT column1, column2, ... FROM table_name WHERE condition;
To fetch the ID, Name and Salary fields from the CUSTOMERS table for a customer with the name Hardik. Note- It is important to note that all the strings should be given inside single quotes (''). Whereas, numeric values should be given without any quote
WHERE NAME = 'Hardik';
To fetch the ID, Name and Salary fields from the CUSTOMERS table, where the salary is greater than 2000. SELECT * FROM CUSTOMERS WHERE SALARY > 2000;
c) Multiplication (x): Multiplies two values. Example- Let a=10 and b= SELECT 10 * 5; (a*b will give the result as 50 ) d) Division (/): Divides one value by another. Example- Let a=10 and b= SELECT 10 / 5; (a/b will give the result as 2 ) e) Modulus (%): Returns the remainder of division. Example- Let a=10 and b= SELECT 10 % 5; (a%b will give the result as 0 )
a) Equal (=): Checks if two values are equal, if yes then condition becomes true. Example- SELECT * FROM CUSTOMERS WHERE ID = 3; b) Not equal to (!= or <>): Checks if two values are not equal, if yes then condition becomes true. Example- SELECT * FROM CUSTOMERS WHERE SALARY != 2000; c) Greater than (>): Checks if one value is greater than another. Example- SELECT * FROM CUSTOMERS WHERE SALARY > 2000;
a) AND: Returns true if all conditions are true. Syntax- SELECT column1, column2, ... FROM table_name WHERE condition1 AND condition2; Example- To fetch the ID, Name and Salary fields from the CUSTOMERS table, where the salary is greater than 2000 and the age is less than 25 years. SELECT ID, NAME, SALARY FROM CUSTOMERS WHERE SALARY > 2000 AND age < 25; b) OR: Returns true if any condition is true. Syntax- SELECT column1, column2, ... FROM table_name WHERE condition1 OR condition2; Example- To fetch the ID, Name and Salary fields from the CUSTOMERS table, where the salary is greater than 2000 OR the age is less than 25 years.
WHERE SALARY > 2000 OR age < 25; c) NOT: It is used to negate a condition. This operator is used to exclude certain records means it helps you find records where the condition is not true. Syntax- SELECT column1, column2, ... FROM table_name WHERE NOT condition; Example- To fetch the ID, Name and Salary fields from the CUSTOMERS table, whose salary is not 2000. SELECT ID, NAME, SALARY FROM CUSTOMERS WHERE NOT SALARY = 2000;