0% found this document useful (0 votes)
7 views2 pages

lab 1

The document outlines SQL commands for creating, altering, dropping tables, and inserting rows, emphasizing the use of constraints. It provides syntax examples for each command, including CREATE, ALTER, RENAME, DROP, and INSERT, along with execution queries demonstrating their use. The result confirms that all specified queries were executed successfully.

Uploaded by

praveench1303
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

lab 1

The document outlines SQL commands for creating, altering, dropping tables, and inserting rows, emphasizing the use of constraints. It provides syntax examples for each command, including CREATE, ALTER, RENAME, DROP, and INSERT, along with execution queries demonstrating their use. The result confirms that all specified queries were executed successfully.

Uploaded by

praveench1303
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

AIM: Creation, altering and droping of tables and inserting rows into a table (use constraints while

creating tables) examples using SELECT command.


Discription: The aim of this task is to design and develop a simple Entity with attirbute set. We in this use
" SQL"language.

Create: used to create the definition of databases, entitites, and views.


Syntax:
create view <view_name> as select <attribute1>,<attribute2>...... from <table_name> where <conditions>;

Alter: This is a DDL command used to alter or update the definition of an entity. using this
command has multiple purposes. they are as follows:
Syntax:
alter table <table_name> add <attribute_name> datatype;
alter table <table_name> drop column <attibute_name>;
alter table <table_name> rename column <attribute_name_old> to <attribute_name_new>;
alter table <table_name> modify <column_name> <datatype>; ------after version 10g of software.
alter table <old_table_name> rename to <new_table_name>;

Rename: As suggested above this can be used to rename entity. but, it can also rename views and DBs.
Syntax:
rename <old_table_name> to <new_table_name>;

Drop: This command is used to remove entity or views from the DB.
Syntax:
drop table <table_name>;

Insert: This command is used to insert the data onto the entity. This has the following syntax.
Syntax:
insert into <table_name> (attribute_1,attribute_2,.....,attribuite_n) values (value11,value12,......value_1n),
(value21,value22,......value_2n);

Select: To display the content of the entity


Syntax:
select * from <table_name>;

Queries with execution:

SQL> create table students (sid number primary key, sname varchar2(20) not null, rank number not null);

Table created.

SQL> alter table students add dept varchar2(5);

Table altered.

SQL> alter table students drop column rank;

Table altered.

SQL> alter table students rename column dept to branch;

Table altered.

SQL> alter table students modify branch varchar2(3) ;

Table altered.
SQL> alter table students rename to sdata;

Table altered.

SQL> insert into Students values (1, 'praveen','CSE');


insert into Students values (1, 'praveen','CSE')
*
ERROR at line 1:
ORA-00942: table or view "SYSTEM"."STUDENTS" does not exist Help: https://docs.
oracle.com/error-help/db/ora-00942/

SQL> insert into sdata values (1,'praveen','CSE'),(2,'satish','CSE') ;

2 rows created.

SQL> desc sdata;

Name Null? Type


----------------------------------------- -------- ----------------------------
SID NOT NULL NUMBER
SNAME NOT NULL VARCHAR2(20)
BRANCH VARCHAR2(3)

SQL> select * from sdata;

SID SNAME BRA


---------- -------------------- ---
1 praveen CSE
2 satish CSE

SQL> drop table sdata;

Table dropped.

SQL>

Result: All the queries related to the task 1 are executed as per the specifications.

You might also like