3.SQL Queries DDL
3.SQL Queries DDL
SQL
DDL-COMMANDS
CREATE
• SQL CREATE TABLE statement is used to create
table in a database.
• If you want to create a table, you should name the
table and define its column and each column's data
type.
• To create the table:
• create table table-name (column-name1 datatype1,
column-name2 datatype2, column-name3
datatype3, column-name4 datatype4 );
create table STUDENTS(id number(10), name
varchar(20), age number(4));
• You can verify it, if you have created the table
successfully by looking at the message displayed by
the SQL Server, else you can use DESC command as
follows:
• SQL> DESC STUDENTS;
Practice:
Create a table Employee having attributes as id,
name, department, age.
Inserting Data into Table
Constraints are used to limit the type of data that can go into a
table. This ensures the accuracy and reliability of the data in the
table. If there is any violation between the constraint and the data
action, the action is aborted.
Example
SELECT * FROM STUDENTS
WHERE name=‘Navjot’;
SQL AND, OR and NOT Operators
1. The AND and OR operators are used to filter records based
on more than one condition.
2. The AND operator displays a record if all the conditions
separated by AND are TRUE.
3. The OR operator displays a record if any of the conditions
separated by OR is TRUE.
4. The NOT operator displays a record if the condition(s) is
NOT TRUE.
SQL AND, OR and NOT Operators
AND Syntax
NOT Syntax
SELECT column1, column2, ...
FROM table_name
WHERE NOT condition;
SQL AND, OR and NOT Operators
AND Example
select all fields from "Customers" where country is "Germany"
AND city is "Berlin":