1.
Write syntax of the written commands
1. Create
2. Insert
3. Select
4. Delete
5. Drop
6. Update
Ans: CREATE TABLE table_name
(column1 datatype null/not null,
column2 datatype null/not null,
...
CONSTRAINT constraint_name PRIMARY KEY (column1, column2, . column_n)
);
INSERT INTO "table_name" ("column1", "column2", ...)
VALUES ("value1", "value2", ...);
SELECT column_name(s)
FROM table_name;
DELETE FROM table_name
WHERE some_column=some_value
DROP INDEX index_name ON table_name
DROP INDEX table_name.index_name
DROP INDEX index_name
DROP TABLE table_name
UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value
2. Create three tables with minimum 5 attributes
1. Employee
2. Customer
3. Department
Ans:
Create table employee
(empno varchar(2) primary key,
Empname varchar(10) not null,
Dept varchar(10),
Sal varchar(10),
Hiredate date};
Create table customer
{custid varchar(2) primary key,
Custname varchar(!0) not null,
Location varchar(10);
Company varchar(10);
Phone varchar(18)
};
CREATE TABLE DEPARTMENT
(DEPTNO CHAR(3) NOT NULL,
DEPTNAME VARCHAR(36) NOT NULL,
LOCATION CHAR(16),
PRIMARY KEY (DEPTNO));
4. Using insert command enter 10 tuples each
Ans. Insert into employee values(01,’sarabjeet’,’IT’,’85000’,’10-10-2008’);
Insert into employee values(‘&empno’,’&empname’,’&dept’,’& sal’,’&hiredate’);
5. Using update command update the data in the above created tables (using
specific conditions also).
Ans.
Update employee set sal=80000 where name=’sarabjeet’;
6. Write various string, mathematical and data functions and give examples.
Ans. String functions:
Length: it is used yo find the length of the string including the count of blank if
any.
LTrim/rtrimk
Its use is to remove the specified character or character from the string until it
happens to be the first on the left or the right.
Select name,Ltrim(name,’AB’) from TR4;
Selectr name , length(RTrim(name,’’)) from try;
Lpad/rpad: its use to pad the string with the specified characteristics from the
left or right.they take 3 arguments:
Select ename , sal ,lpad(sal,10,’*’)
From emp;
Select ename ,sal,rpad(sal,3,’*’)from emp;
6. Explain
1 ) Create the table by the name employee_master which includes the fields emp_id
as primary key, emp_name, emp_age, emp_address, emp_department,
emp_location.
2) Insert 10 records using insert statement.
3) Delete the records where emp_age is between 30 to 40
4) Update those records in which employee address is rohini to dwarka.
5) Rename the table from employee_master to emp_master.