当前位置:网站首页>Microsoft SQL Server database language and function usage (XIII)
Microsoft SQL Server database language and function usage (XIII)
2022-07-23 22:13:00 【Pzz_ Lite】
Microsoft SQL Server Database language and function use ( 13、 ... and )
notes : Use Microsoft SQL Server 2019
One 、 Use SQL Statement backup
1、SQL Server Statement backup
(1)、 Use SQL Statement to back up the database , grammar :Backup Database Database name To disk=‘ Storage location .bak’
In statement Database Add the database name later , Followed by the storage location path .
(2)、 Restore the database with script file , First, generate the script file from the database , Select a database , Right mouse button : Mission –> Generation script , Check “ Save as script file ”, Choose a suitable location for file saving , Click Advanced , Select the penultimate “ The type of data to script ” choice “ Architecture and data ” If only the schema is selected, the exported script database has no data , After exporting the script file, open the script file to get the statement information of the database , After execution, you can restore the database .

(3)、 Use SQL Statement to restore the database , When restoring a database, you need to select another database , For example, when using the current restore database , Report errors :RESTORE Unable to process database ‘CZSPGL’, Because it is being used by this session . It is recommended to use master database .
Two 、 Database attachment
(1)、 Select database, right click to attach database , Select Add database , At this time, there is a default path to the database , Add the selected database to add ( It may not be able to attach , The reason is the database permission problem , At this time, you can copy the path in “ My computer ” Paste the search path in , There may also be custom database paths , Just find the storage path of the database .

(2)、 hold SQL The copy path of the attached database is found in the file ( The database is stored in the user-defined path. Find the corresponding path ), Can find SQL The default database path , At this time, it is found that there are two files in the database to be searched , One is the main file of the database , One is the script log file of the database . Select the database file you want to attach and right-click to open “ attribute ”–> choice “ Security ”–> Click on “ edit ”–> Click on “ add to ”–> find “Everyone” Or specify the object , Click OK to check the permission of the object to the database, such as “ Complete control of ”、“ modify ”、“ Read and execute ”、“ Reading and writing ”、“ write in ”, In addition, the corresponding log script file is also operated , This step is to make sure that the database is in SQL Server When the database is attached, it cannot be attached because of permissions .
3、 ... and 、 jurisdiction
1、 In order to restrict developers of different applications to only access their own databases , And can't see ( Or you can see whether it can be operated ) Number of other applications Database , Now we need to give it to the developers of various applications Member limits Authority , Let them login SQL Server Only authorized databases can be seen, but other databases cannot be seen .
(1)、 Add specific users to a database for use .
①、 choice “ Security ”–>“ Login name ” Right mouse button “ New login ”, Rename login name “ choice SQL Server Authentication ” Set the password , hold “ The user must change the password at the next login ” Check out , Select the default database ( That is, specify the database used by the user ).
②、“ In the server role ” By default, check “public”, stay “ User mapping ” Check the database for the specified operation , At this time, the user name of the database appears , Select the corresponding database structure after the user name , Then check... Below “db_owner”.
③、 After the specified user operates a specific database, you can see , In this database “ Security ” Medium “ user ” One more. “Dema_user” user , And then in SQL Server“ Security ” There is also a “Dema_user”, Although the name is the same, the two user levels are different , That is, users existing in each database can only operate the database , And in the SQL Server Users in can log in and operate the database separately .
(2)、 Specify the user to operate the specified database
①、 Now log in with the user you created , After logging in successfully, you can see all databases , But when the operation is not the specified database, it will display “ Unable to access the database ” Because the database that the user has permission to use is not specified when creating the user, it is inaccessible , Therefore, the user can only operate the specified database, such as : Set the database “Text_Demo”.
(3)、 Use SQL Server Statement login account add and delete objects .
①、 Use in the account with the highest authority SQL Statement to create an account in the new query , Use use master go
exec sp_addlogin + title of account ,+ password , Statement to create an account , After successfully executing the command, disconnect the account with the highest permission and log in with the account just created .
②、 Specify the database to be used for the created account , Log in with the new account and then log in to the original account with the highest permission , Find the database you want to specify in the database of the highest authority user , Such as Demo Then create a new query , Use use Demo
Go exec sp_grantdbaccess ‘ Associate the new account name ’,‘ Specify the database user ’.
③、 Use the new account operation to specify the database , After the command is executed, go to create user login , namely Text_Demo2 Then you can check Demo Database , But only the database can be viewed here , However, it still needs one step to operate the database .
④、 Return to the highest authority account , stay Demo Create a new query in the database , Use sp_addrolemember Key words to Text_Demo2 Account assignment operation Demo jurisdiction , Because the front is Demo In the database, I set up a separate account to operate the database “Demo_user” So just compare this account with the new account “Text_Demo2 ” After Association ,“Text_Demo2 ” You can do that. Demo Database operation .
(3)、 If the database is automatically backed up , During the process of adding a maintenance plan “SQL Server agent ( Agent Disabled XP)” Unable to open agent , First open SQL Server Found in the corresponding configuration manager “SQL Server service ” hold “SQL Server agent ” The service starts manually , Then back SQL Server Zhongba “SQL Server agent ( Agent Disabled XP)” Start and then perform automatic database backup .
(4)、 If the agent cannot be started in the first step , have access to SQL Server Statement to create a maintenance plan , Create a new query in the database you want to back up automatically , Enter the following statement and execute , After the command is successfully executed, refresh it, and then “ Maintenance plan ” You can create a new maintenance plan in .
边栏推荐
- How ZK solves the problem of cerebral fissure
- 02. Supplement of knowledge related to web page structure
- Machine learning exercises -- right rate regression
- Taoying collects goods in batches. How to save the babies that have not been uploaded and then import them later
- 除了钱,创业者还需要什么?专访明月湖创赛创投机构
- Neo4j应用
- Bisection function details
- Sudoku written for once and for all
- JDBC programming of MySQL
- Taobao assistant is disabled. What is the reason for using the big Taoying import data package to upload the baby prompt "the main image is required and cannot be empty"? How to solve it?
猜你喜欢

Cookie 和 Session

synthesizable之Verilog可不可综合

Taoying collects goods in batches. How to save the babies that have not been uploaded and then import them later

Wangxuegang video coding -- mediacodec coding and decoding

jedis 6---redisson和jedis的入门和不同

Multithreading problem: why should we not use multithreading to read and write the same socket connection?

MySQL的JDBC編程

ONEFLOW V0.8.0 officially released

Leetcode high frequency question 53. maximum subarray sum, continuous subarray with maximum sum, return its maximum sum

02. Supplement of knowledge related to web page structure
随机推荐
淘宝助理停用,用大淘营导入数据包上传宝贝提示“主图为必填项,不能为空”是什么原因?如何解决?
[golang learning notes] concurrency basis
I, AI doctoral student, online crowdfunding research topic
Mqtt connection, subscription and publishing can be realized without mqtt C library
Record the process of the first excavation and intersection
Apprentissage Lambda (utilisation du comparateur après tri, regroupement après collecte avec collectors.groupingby)
Jedis 6 - Introduction and difference between redisson and jedis
U++ events
实时监控Mysql数据库变化_进行数据同步_了解Canal_---Canal工作笔记001
MySQL的JDBC編程
U++学习笔记 基础人物轴绑定及映射绑定
02.网页结构相关知识补充
[acwing] weekly competition
疯狂的牛市,下半场何去何从?2021-04-30
达梦数据库tools包中的工具(操作达梦数据库)
Golang invalid argument to intn报错的解决
Matlab小波工具箱导入信号出错(doesn‘t contain one dimensional Singal)
大学数据库创建与查询实战——数据库表设计
初探POC编写
MVVM和MVVMLight简介及项目开发(一)