0% found this document useful (0 votes)
81 views

SQL1

Here are the steps to complete the lab practice assignment: 1. Create a table EMPLOYEE with the given schema 2. Add a new column HIREDATE to the existing EMPLOYEE table 3. Modify the datatype of the JOB_ID column from char to varchar2 4. Modify the name of the Emp_no column to E_no 5. Modify the column width of the JOB field
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views

SQL1

Here are the steps to complete the lab practice assignment: 1. Create a table EMPLOYEE with the given schema 2. Add a new column HIREDATE to the existing EMPLOYEE table 3. Modify the datatype of the JOB_ID column from char to varchar2 4. Modify the name of the Emp_no column to E_no 5. Modify the column width of the JOB field
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

DDL commands of SQL

PostgreSQL Data Types


Overview of PostgreSQL data types
PostgreSQL supports the following data types:
•Boolean
•Character types such as char, varchar, and text.
•Numeric types such as integer and floating-point number.
•Temporal types such as date, time, timestamp, and interval
•UUID for storing Universally Unique Identifiers
•Array for storing array strings, numbers, etc.
•JSON stores JSON data
•hstore stores key-value pair
•Special types such as network address and geometric data.
PostgreSQL CREATE TABLE syntax
A relational database consists of multiple related tables. A table consists of rows and
columns. Tables allow you to store structured data like customers, products, employees, etc.

To create a new table, you use the CREATE TABLE statement. The following illustrates the basic
syntax of the CREATE TABLE statement:
CREATE TABLE [IF NOT EXISTS] table_name (
column1 datatype(length) column_contraint,
column2 datatype(length) column_contraint,
column3 datatype(length) column_contraint,
table_constraints
);
CREATE:
(a)CREATE TABLE: This is used to create a new relation (table) Syntax:
CREATE TABLE (field_1 data_type(size),field_2 data_type(size), .. . );

SQL> CREATE TABLE Student (sno NUMBER (3), sname CHAR (10), class
CHAR (5));
INSERT
• INSERT INTO: This is used to add records into a relation. These are
three type of INSERT INTO queries which are as

Syntax: INSERT INTO < relation/table name> (field_1,field_2……


field_n)VALUES (data_1,data_2,........data_n);
SQL>INSERT INTO student(sno,sname,class,address)VALUES (1,’XYZ’,
’b.Tech’, ’ABC’);
Inserting multiple records
• Syntax: INSERT INTO relation_name field_1,field_2,.....field_n) VALUES
(&data_1,&data_2,........&data_n);
• Example:
• SQL>INSERT INTO student (sno, sname, class,address) VALUES
(&sno,’&sname’,’&class’,’&address’); Enter value for sno: 101 Enter
value for name: XYZ Enter value for class: B.Tech Enter value for name:
ABC
• DROP TABLE: This is used to delete the structure of a relation. It
permanently deletes the records in the table.
• Syntax: DROP TABLE relation_name;
• Example: SQL>DROP TABLE std;
ALTER:
• ALTER TABLE ...ADD...: This is used to add some extra fields into
existing relation.
Syntax: ALTER TABLE relation_name ADD (new field_1 data_type(size),
new field_2 data_type(size),..);
Example: SQL>ALTER TABLE std ADD (Address CHAR(10));
ALTER TABLE...MODIFY
• ALTER TABLE...MODIFY...: This is used to change the width as well as
data type of fields of existing relations.
• Syntax: ALTER TABLE relation_name MODIFY (field_1
newdata_type(Size), field_2
newdata_type(Size),....field_newdata_type(Size));
• Example:SQL>ALTER TABLE student MODIFY(sname
VARCHAR(10),class VARCHAR(5))
DELETE
• DELETE-FROM: This is used to delete all the records of a relation but it
will retain the structure of that relation.
DELETE-FROM: This is used to delete all the records of relation.
Syntax: SQL>DELETE FROM relation_name;
Example: SQL>DELETE FROM std;
• TRUNCATE: This command will remove the data permanently. But
structure will not be removed.

• Syntax: TRUNCATE TABLE <Table name>


• Example TRUNCATE TABLE student;
• To Retrieve data from one or more tables.
SELECT FROM: To display all fields for all records.
Syntax : SELECT * FROM relation_name;
Example : SQL> select * from dept;
LAB PRACTICE ASSIGNMENT:

1. Create a table EMPLOYEE with following schema:


(Emp_no, E_name, E_address, E_ph_no, Dept_no, Dept_name,Job_id ,
Salary)
2. Add a new column; HIREDATE to the existing relation.
3. Change the datatype of JOB_ID from char to varchar2.
4. Change the name of column/field Emp_no to E_no.
5. Modify the column width of the job field of emp table

You might also like