linux关闭sql server,Linux系统中数据库启动和关闭&Basic SQL-Unix

第一步:使用oracle用户登录

第二步:在oracle用户下输入sqlplus /nolog

第三步:如需使用管理员权限,则输入connect /as sysdba

第四步:启动和关闭

startup

startup nomount #只启动实例

startup mount   #打开控制文件

startup open    #打开数据文件和重做日志

shutdown

shutdown normal        #不接受新的连接,需要等待所有的用户断开连接

shutdown immediate     #回滚未结束的事务关闭数据库

shutdown transactional #等用户结束事务关闭数据库

shutdown abort         #直接关闭数据库

第五步:如果是启动服务,要开启监听

退出sqlplus模式输入lsnrctl start

[oracle@RHEL64 ~]$ sqlplus /nolog

SQL*Plus:>  Copyright (c) 1982, 2009, Oracle.  All rights reserved.

SQL> conn /as sysdba

Connected to an>  SQL> startup

ORACLE instance started.

Total System Global Area  551165952 bytes

Fixed>

Variable>  Database Buffers          171966464 bytes

Redo Buffers                3690496 bytes

Database mounted.

Database opened.

SQL>

解锁scott用户:

SQL>>

User>  SQL> commit;

Commit complete.

SQL> conn scott/tiger

ERROR:

ORA-28001: the password has expired

Changing password for scott

New password:

Retype new password:

Password changed

Connected.

显示当前用户:

SQL> show user

USER is "SCOTT"

设置SQL*Plus的环境变量:linesize和pagesize

SQL> set linesize 300

SQL> set pagesize 3000

计算一个查询花费的时间:

SQL> set timing on

SQL> select * from dept;

DEPTNO DNAME          LOC

---------- -------------- -------------

10 ACCOUNTING     NEW YORK

20 RESEARCH       DALLAS

30 SALES          CHICAGO

40 OPERATIONS     BOSTON

Elapsed: 00:00:00.07

SQL>

emp,dept,salgrade表结构如下:

DEPT表:

302bad67f9dda864b7616bad5169f95e.gif

DSC0000.jpg (27.18 KB, 下载次数: 2)

2018-10-24 06:51 上传

EMP表:

302bad67f9dda864b7616bad5169f95e.gif

DSC0001.jpg (129.77 KB, 下载次数: 3)

2018-10-24 06:51 上传

salgrade表:

302bad67f9dda864b7616bad5169f95e.gif

DSC0002.jpg (18.97 KB, 下载次数: 2)

2018-10-24 06:51 上传

查询emp表中所有人的姓名:

SQL> select ename from emp;

ENAME

----------

SMITH

ALLEN

WARD

JONES

MARTIN

BLAKE

CLARK

SCOTT

KING

TURNER

ADAMS

JAMES

FORD

MILLER

14 rows selected.

SQL>

把查询结果中ename改为中文“姓名”:

SQL> select ename 姓名 from emp;

查询emp表中不重复的部门:

SQL> select distinct deptno from emp;

DEPTNO

----------

30

20

10

SQL>

查询emp表中工资大于2k的员工:

SQL> select ename,sal from emp where sal>2000;

ENAME             SAL

---------- ----------

JONES            2975

BLAKE            2850

CLARK            2450

SCOTT            3000

KING             5000

FORD             3000

6 rows selected.

SQL>

查询emp表中工资3k到3k的员工:

SQL> select ename,sal from emp where sal between 2000 and 3000;

ENAME             SAL

---------- ----------

JONES            2975

BLAKE            2850

CLARK            2450

SCOTT            3000

FORD             3000

SQL>

查询emp表中,ename列以A开头的员工:

SQL> select ename from emp where ename like 'A%';

ENAME

----------

ALLEN

ADAMS

SQL>

查询emp表中,ename列含有A的员工:

SQL> select ename from emp where ename like '%A%';

ENAME

----------

ALLEN

WARD

MARTIN

BLAKE

CLARK

ADAMS

JAMES

7 rows selected.

SQL>

查询没有员工的部门:

SQL> select * from dept where deptno in (select deptno from emp group by deptno having count(*)

查询有员工的部门:

SQL> select * from dept where deptno in (select deptno from emp group by deptno having count(*)>1);

DEPTNO DNAME          LOC

---------- -------------- -------------

30 SALES          CHICAGO

20 RESEARCH       DALLAS

10 ACCOUNTING     NEW YORK

SQL>

查询emp表中姓名和工资额,按照工资降序排列:

SQL> select ename,sal from emp order by sal desc;

ENAME             SAL

---------- ----------

KING             5000

FORD             3000

SCOTT            3000

JONES            2975

BLAKE            2850

CLARK            2450

ALLEN            1600

TURNER           1500

MILLER           1300

WARD             1250

MARTIN           1250

ADAMS            1100

JAMES             950

SMITH             800

14 rows selected.

SQL>

查询emp表中补贴为null的员工:

SQL> select ename,comm from emp where comm is null;

ENAME            COMM

---------- ----------

SMITH

JONES

BLAKE

CLARK

SCOTT

KING

ADAMS

JAMES

FORD

MILLER

10 rows selected.

SQL>

使用to_char函数查询1981年入职的员工:

SQL> select ename,hiredate from emp where to_char(hiredate,'yyyy')='1981';

ENAME      HIREDATE

---------- ---------

ALLEN      20-FEB-81

WARD       22-FEB-81

JONES      02-APR-81

MARTIN     28-SEP-81

BLAKE      01-MAY-81

CLARK      09-JUN-81

KING       17-NOV-81

TURNER     08-SEP-81

JAMES      03-DEC-81

FORD       03-DEC-81

10 rows selected.

SQL>

使用nvl函数查询每个人每个月的总收入,如果补贴为null,则视其为0:

SQL> select ename,sal+nvl(comm,0),comm from emp;

ENAME      SAL+NVL(COMM,0)       COMM

---------- --------------- ----------

SMITH                  800

ALLEN                 1900        300

WARD                  1750        500

JONES                 2975

MARTIN                2650       1400

BLAKE                 2850

CLARK                 2450

SCOTT                 3000

KING                  5000

TURNER                1500          0

ADAMS                 1100

ENAME      SAL+NVL(COMM,0)       COMM

---------- --------------- ----------

JAMES                  950

FORD                  3000

MILLER                1300

14 rows selected.

SQL>

查询emp表中哪些员工补贴比工资还高:

SQL> select ename,sal,comm from emp where comm>sal;

ENAME             SAL       COMM

---------- ---------- ----------

MARTIN           1250       1400

SQL>

查询每个部门的最高工资:

SQL> select deptno,max(sal) from emp group by deptno;

DEPTNO   MAX(SAL)

---------- ----------

30       2850

20       3000

10       5000

SQL>

查询每个部门是那个员工获得了部门的最高工资:

SQL> select e1.ename,e1.sal,e1.deptno from emp e1,(select deptno,max(sal)最大值 from emp group by deptno) e2 where e1.deptno=e2.deptno and e1.sal=e2.最大值;

ENAME             SAL     DEPTNO

---------- ---------- ----------

BLAKE            2850         30

SCOTT            3000         20

KING             5000         10

FORD             3000         20

SQL>

查询10号部门和20号部门平均工资的差异:

SQL> select (select avg(sal) from emp where deptno=10)-(select avg(sal) from emp where deptno=20) distance from dual;

DISTANCE

----------

741.666667

SQL>

查询emp表每个员工和最高工资之间的差距:

SQL> select ename,(select max(sal) from emp)-sal distan from emp;

ENAME          DISTAN

---------- ----------

SMITH            4200

ALLEN            3400

WARD             3750

JONES            2025

MARTIN           3750

BLAKE            2150

CLARK            2550

SCOTT            2000

KING                0

TURNER           3500

ADAMS            3900

ENAME          DISTAN

---------- ----------

JAMES            4050

FORD             2000

MILLER           3700

14 rows selected.

SQL>

查询emp表中工资超过平均工资的员工:

SQL> select ename,sal from emp where sal>(select avg(sal) from  emp);

ENAME             SAL

---------- ----------

JONES            2975

BLAKE            2850

CLARK            2450

SCOTT            3000

KING             5000

FORD             3000

6 rows selected.

SQL>

查询每个部门中工资超过平均工资的员工:

SQL> select deptno,ename,sal from emp where sal>(select avg(sal) from  emp);

DEPTNO ENAME             SAL

---------- ---------- ----------

20 JONES            2975

30 BLAKE            2850

10 CLARK            2450

20 SCOTT            3000

10 KING             5000

20 FORD             3000

6 rows selected.

SQL>

列出所有部门的详细信息和部门人数:

SQL> select a.*,(select count(*) from emp where deptno=a.deptno) total from dept a;

DEPTNO DNAME          LOC                TOTAL

---------- -------------- ------------- ----------

10 ACCOUNTING     NEW YORK               3

20 RESEARCH       DALLAS                 5

30 SALES          CHICAGO                6

40 OPERATIONS     BOSTON                 0

SQL>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
The LPIC-1 Authorized Cert Guide has a single goal: to help you pass the new version of the Linux Professional Institute LPIC-1 exams. The most comprehensive and time-efficient LPIC-1 study guide available, it's an extraordinarily cost-effective alternative to expensive training: a perfect resource for all LPIC-1 candidates. Authored by a leading LPI insider and long-time Linux trainer, it presents focused, straight-to-the-point coverage of all LPIC-1 exam topics, including: System Architecture Linux Installation and Package Management GNU and Unix Commands Devices, Linux Filesystems, Filesystem Hierarchy Standard Shells, Scripting and Data Management User Interfaces and Desktops Administrative Tasks Essential System Services Networking Fundamentals Security From start to finish, it's organized to help you focus your study time where you need the most help, so you can retain more, and earn higher scores: Pre-chapter "Do I Know This Already" (DIKTA) quizzes help you assess your knowledge of each chapter's content, and decide how much time to spend on each section Foundation Topics sections thoroughly explain concepts and theory, and link them to real-world configurations and commands Key Topics icons flag every figure, table, or list you absolutely must understand and remember Chapter-ending Exam Preparation sections deliver even more exercises and troubleshooting scenarios Two full sample exams offer realistic practice delivered through Pearson's state-of-the-art PCPT test engine Table of Contents Chapter 1 Installing Linux Chapter 2 Boot Process and Runlevels Chapter 3 Package Install and Management Chapter 4 Basic Command Line Usage Chapter 5 File Management Chapter 6 Text Processing/Advanced Command Line Chapter 7 Process Management Chapter 8 Editing Text Chapter 9 Partitions and Filesystems Chapter 10 Permissions and Ownership Chapter 11 Customizing Shell Environments Chapter 12 Shell Scripting Chapter 13 Basic SQL Management Chapter 14 Configuring User Interfaces and Desktops Chapter 15 Managing Users and Groups Chapter 16 Schedule and Automate Tasks Chapter 17 Configuring Print and Email Services Chapter 18 Logging and Time Services Chapter 19 Networking Fundamentals Chapter 20 System Security Chapter 21 Final Preparation Appendix A: Answers to the “Do I Know This Already?” Quizzes and Review Questions Appendix B: Study Planner
要在Linux上安装SQL Server数据库,可以按照以下步骤进行操作: 1. 首先,执行以下命令来移除旧的mssql-tools和unixODBC-utf16-devel软件包: ``` sudo yum remove mssql-tools unixODBC-utf16-devel ``` 2. 然后,使用以下命令来安装mssql-tools和unixODBC-devel软件包: ``` sudo yum install mssql-tools unixODBC-devel -y ``` 3. 接下来,下载Microsoft SQL Server 2017 Red Hat存储库配置文件,并将其保存到/etc/yum.repos.d/mssql-server.repo: ``` sudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/7/mssql-server-2017.repo ``` 4. 最后,执行以下命令来安装SQL Server数据库: ``` sudo yum install -y mssql-server ``` 在执行安装过程,如果缺少任何依赖项,可以使用yum命令来安装补齐。安装完成后,可以执行SQL Server初始化操作。123 #### 引用[.reference_title] - *1* *2* [Linux安装SQLServer数据库](https://blog.csdn.net/m0_52735414/article/details/128968624)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}} ] [.reference_item] - *3* [LinuxSQL Server数据库安装](https://blog.csdn.net/carefree2005/article/details/128207254)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值