mysql 常用数据库语句 小练习
一个mysql小练习 建表 查询 修改表 增加字段 删除字段
闲来无事,上班时找了个练习来写,联系题目是针对sql server 2000的以下为mysql一 单词解释(2分/个) 34分
Data 数据 Database 数据库 RDBMS 关系数据库管理系统 GRANT 授权
REVOKE 取消权限 DENY 拒绝权限 DECLARE 定义变量 PROCEDURE存储过程
事务 Transaction 触发器 TRIGGER 继续 continue 唯一 unqiue
主键 primary key 标识列 identity 外键 foreign key 检查 check
约束 constraint
--------------------------------------------------------------------
1) 创建一张学生表,包含以下信息,学号,姓名,年龄,性别,家庭住址,联系电话
create table student
(
学号 int,
姓名 varchar(10),
年龄 int,
性别 varchar(4),
家庭住址 varchar(50),
联系电话 varchar(11)
);
--------------------------------------------------------------------
2) 修改学生表的结构,添加一列信息,学历
alter table student add column 学历 varchar(6);
--------------------------------------------------------------------
3) 修改学生表的结构,删除一列信息,家庭住址
alter table student drop column 家庭住址;//注意此处用drop而非delete
--------------------------------------------------------------------
4) 向学生表添加如下信息:
学号 姓名年龄性别联系电话学历
1A22男123456小学
2B21男119中学
3C23男110高中
4D18女114大学
insert into student (学号,姓名,年龄,性别,联系电话,学历) values(1,"A",22,"男","123456","小学");
insert into student (学号,姓名,年龄,性别,联系电话,学历) values(1,"B",21,"男","119","中学");
insert into student (学号,姓名,年龄,性别,联系电话,学历) values(1,"C",23,"男","123456","高中");
insert into student (学号,姓名,年龄,性别,联系电话,学历) values(1,"D",23,"女","114","大学");
--------------------------------------------------------------------
5) 修改学生表的数据,将电话号码以11开头的学员的学历改为“大专”
update student set 学历="大专" where 联系电话 like "11%";
--------------------------------------------------------------------
6) 删除学生表的数据,姓名以C开头,性别为‘男'的记录删除
delete from student where 姓名 like "C" and 性别="男";
--------------------------------------------------------------------
7) 查询学生表的数据,将所有年龄小于22岁的,学历为“大专”的,学生的姓名和学号示出来
select 姓名,学号 from student where 年龄--------------------------------------------------------------------
8) 查询学生表的数据,查询所有信息,列出前25%的记录
select top 25 percent * from student ; ????
select * from student limit 25%;????
这条有问题,在sql 2000中应该是select top 25 percent * from student ;
--------------------------------------------------------------------
9) 查询出所有学生的姓名,性别,年龄降序排列
select 姓名,性别,年龄 from student order by 年龄 desc;
--------------------------------------------------------------------
10) 按照性别分组查询所有的平均年龄
select avg(年龄) as 平均年龄 from student group by 性别;
select avg(年龄) from student group by 性别;
select avg(年龄) 平均年龄 from student group by 性别;
--------------------------------------------------------------------
3) 说出以下聚合数的含义:avg ,sum ,max ,min , count ,count(*)
AVG:求平均值
SUM:求和
MAX:求最大值
MIN:求最小值
COUNT(*):返回所有行数
COUNT返回满足指定条件的记录值

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



You can open phpMyAdmin through the following steps: 1. Log in to the website control panel; 2. Find and click the phpMyAdmin icon; 3. Enter MySQL credentials; 4. Click "Login".

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

Redis uses a single threaded architecture to provide high performance, simplicity, and consistency. It utilizes I/O multiplexing, event loops, non-blocking I/O, and shared memory to improve concurrency, but with limitations of concurrency limitations, single point of failure, and unsuitable for write-intensive workloads.

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

Effective monitoring of Redis databases is critical to maintaining optimal performance, identifying potential bottlenecks, and ensuring overall system reliability. Redis Exporter Service is a powerful utility designed to monitor Redis databases using Prometheus. This tutorial will guide you through the complete setup and configuration of Redis Exporter Service, ensuring you seamlessly build monitoring solutions. By studying this tutorial, you will achieve fully operational monitoring settings

The methods for viewing SQL database errors are: 1. View error messages directly; 2. Use SHOW ERRORS and SHOW WARNINGS commands; 3. Access the error log; 4. Use error codes to find the cause of the error; 5. Check the database connection and query syntax; 6. Use debugging tools.

Apache connects to a database requires the following steps: Install the database driver. Configure the web.xml file to create a connection pool. Create a JDBC data source and specify the connection settings. Use the JDBC API to access the database from Java code, including getting connections, creating statements, binding parameters, executing queries or updates, and processing results.
