Creating tables:
Create table statement is used to create a new table. Its syntax is as follows.
Create table table-name
(column1 datatype, column2 datatype);
Examples:
Create table student
(rollno numeric(4), name varcher(30), address varchar(50), dob date);
Altering an existing table:
The alter table statement is used to add or drop columns in an existing table. It is also used to change the data type of an exsisting field of the table.
Alter table table-name
Add column-name datatypes;
Example:
Alter table student
Add cellno varchar(15);
alter table student
drop column city:
alter table student
modify (city, vorchar(50);
deleting a table:
drop statement is used to delete a table
eg drop table student
truncating a table:
the truncate table statement is used to delete all data in a table. It doesn’t delete the table structure.
Eg truncate table student;
Primary key:
Create table student
(rollno numeric(4) primary key,
Name varcher(25)
f-name varchar(25)
address varcher(50));
foreign key:
create table course
(course-id varcher(10) primary key
Course-name varcher(25) not null
Rollno numeric(4) reference student);
Data manipulation language:
Insert into statement is used to insert new rows in a table. The syntax of this statement is a follows
Syntax:
Insert into table_name
Value ( value1, value2…)
Example:
Insert into student
Values (1,’akmal’,’asad’, ‘mzd’);
Insert into student( rollno, name, fname, city)
Values(1, ’amjad’ , ‘ashraf’, ‘bagh’);
the update statement:
the update statement is used to modify the existing data in a table.
Syntax:
Update table-name
Column-name=new-value
Where column-name=same-value;
Example:
Update student set name=”Danish”
Where rollno=2;
Delete statement:
The delete statement is used to delete a row in a table.
Deleter from student where name=”danish”;
Delete all rows:
Delete from student;
0 comments:
Post a Comment