当前位置:网站首页>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 .
边栏推荐
- DBSCAN point cloud clustering
- MySQL index transaction
- Description and implementation of throttling and anti shake
- Neo4j application
- Leetcode high frequency question 53. maximum subarray sum, continuous subarray with maximum sum, return its maximum sum
- MySQL如何对SQL做prepare预处理(解决IN查询SQL预处理仅能查询出一条记录的问题)
- 大淘营批量采集商品,如何将未上传的宝贝保存下来等后面再导入采集上传
- Sudoku written for once and for all
- 还在为XShell破解烦恼,试试tabby
- Mqtt connection, subscription and publishing can be realized without mqtt C library
猜你喜欢

lambda學習(sort後面的Comparator的使用,collection後使用Collectors.groupingBy分組)

JMeter performance comprehensive practice - sign in and batch sign in

Euclidean clustering (API) and its single tree segmentation

Yolo7 mask recognition practice

138 - query case - knowledge points involved: foreach traversal & computed calculation attributes & V-for loop

Preliminary discussion on POC compilation

Matlab小波工具箱导入信号出错(doesn‘t contain one dimensional Singal)

Stm32+esp8266+mqtt protocol connects Alibaba cloud Internet of things platform

10道面试基础笔试题,你能对几题?

Cookies and sessions
随机推荐
Quick review of interview (III): probability theory and mathematical statistics
[hiflow] Tencent cloud's new generation of automation assistant, which I used to complete the enterprise epidemic prompt (no code)
JS - event proxy and application scenarios
U++学习笔记 基础人物轴绑定及映射绑定
lambda学习(sort后面的Comparator的使用,collection后使用Collectors.groupingBy分组)
A stack of digital robots were selected in Gartner's China AI market guide
el-select下拉框多选远程搜索反显
Leetcode high frequency question 62. different paths: how many paths does the robot have from the upper left corner to the lower right corner? Pure probability permutation and combination problem, not
Real time monitoring of MySQL database changes_ Synchronize data_ Learn about canal_--- Canal work notes 001
Record the process of the first excavation and intersection
Yuanqi Digitalization: existing mode or open source innovation Lixia action
What are the product life cycle, common project functions, and information flow
ApplicationContext introduction
【学习笔记】树的直径,重心
Neo4j应用
PCL error: error c2589 "(": "::" illegal mark on the right)
TreeMap
【golang学习笔记】flag包的简单使用,命令行解析
Microsoft SQL Server数据库语言及功能使用(十三)
[acwing] weekly competition