Sample DB
Sample DB
ID int NOT NULL UNIQUE PRIMARY KEY, // to creates a NOT NULL UNIQUE constraint
on the a single column "ID" column when the "Persons" table is created
Age int
);
create table course1(cid varchar(20) unique , lec_name varchar(10),dept varchar(20))// used to create new table
alter table course1 add chrs varchar(12)// this column used to add new column in our table
alter table course drop column lec_name// his statment used to drop lec-name column from our table
ALTER TABLE Persons ADD PRIMARY KEY (ID); // for single column
);
ALTER TABLE course ALTER COLUMN lec_name SET DEFAULT 'abebe' // to add a defoult values for a
column lec_name
ALTER TABLE course ALTER COLUMN lec_name DROP DEFAULT //to drop default values from column
lec_name
ALTER TABLE course ADD CHECK (age>10) //to add check constraint…but you should adding age column in
the course table
ALTER TABLE course DROP CONSTRAINT chk_course //to drop cheack constraint
alter table course alter column age varchar(10) //to change data types
drop database dmu //this statment used to drop the entire dmu database
drop table course1 // this statment used to drop the entire course1 table
EXEC sp_renamedb 'dmiot', 'dmu'// this statment used to change our data base names
insert into course1 values('1220','chala','SE')// his statment used to insert new data into our table
update course1 set lec_name='alemu' where cid='1220'//this statment used to change the course1 table by changing
chala by alemu
delete from course1 where cid='1220' this statment used to delete data from course1 table where cid=1220
delete * from course1 // this statment used to delete all records from course1 table
select* from course1 //this statment used to display all records in student table
Select top 2 cid From course1 // this statment used to display only top two records from cid column
backup database dmiot TO DISK ='C:\ SE.ldf'// this statment used to take back-up data and put in local C
restore database dmiot from DISK ='C:\ SE.ldf' //this statment used to recover/restore the lost data base