常见数据库笔试题

Q 1. 数据表student有id,name,score,city字段,其中name中的名字可有重复,需要消除重复行,请写sql语句

select  distinct  name  from  student

Q 2 . 数据库优化查询方法

外键、索引、联合查询、选择特定字段等等

 Q 3 . SQL的删除都包括什么?

delete、drop、remove、update、truncate

Q 4 .Q 3中删除操作的用法分别是

1.  delete:用于满足条件的某一行,或者删除表内的所有行

Delete * from table 表名 where……

Delete from table 表名   where……

2.  Drop:用于删除数据表或数据库,或删除数据表字段。

            删除数据表:(表的结构、属性、索引也会被删除)

                use 数据库名称

                drop table 数据表1名称,数据表2名称

            删除数据表字段(列):

                use 数据库名称

                alter table 数据表名称

                drop column 字段名(列名称)

3.   remove:删除数据库文件

alter database Mydatabase1

removefile Mydatabase1_log  

 4.  Truncate:删除数据表中的数据(仅数据表中的数据,不删除表)。

truncatetable 数据表名称


Q 5 .  写5条常用sql语句

select * from student

show tables

desc student

update student  set city='北京' where id=5

delete  from student where id=7

你可能感兴趣的:(常见数据库笔试题)