当前位置:网站首页>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 .
边栏推荐
- Financial products with an annual yield of 6%
- MySQL索引事务
- Storage structure and management disk. It's a bit like installing Win98. You need to partition and format the hard disk first
- jedis 6---redisson和jedis的入门和不同
- 疯狂的牛市,下半场何去何从?2021-04-30
- Sixty final review questions of software architecture
- 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?
- 如何徹底强制殺死後臺無關進程?
- MySQL的JDBC编程
- ONEFLOW V0.8.0 officially released
猜你喜欢

记第一次挖洞交洞历程

el-select下拉框多选远程搜索反显

Apprentissage Lambda (utilisation du comparateur après tri, regroupement après collecte avec collectors.groupingby)

How to add an operator in ONEFLOW

10 basic written interview questions, how many questions can you answer?

How ZK solves the problem of cerebral fissure

Sudoku written for once and for all

Storage structure and management disk. It's a bit like installing Win98. You need to partition and format the hard disk first

El select drop-down box multi selection remote search anti display

ONEFLOW V0.8.0 officially released
随机推荐
MySQL如何对SQL做prepare预处理(解决IN查询SQL预处理仅能查询出一条记录的问题)
Microsoft SQL Server数据库语言及功能使用(十三)
人生总需要一点激情
University database creation and query practice -- database table design
ESP32 的 I2C 原理 & 应用入门
Uniapp uses canvas to write a circular progress bar
软件体系结构期末复习六十题
Neo4j应用
MySQL的 DDL和DML和DQL的基本语法
02.网页结构相关知识补充
Preliminary discussion on POC compilation
实时监控Mysql数据库变化_进行数据同步_了解Canal_---Canal工作笔记001
El upload realizes the preview of uploaded files
STM32 MCU uses ADC function to drive finger heartbeat detection module
El select drop-down box multi selection remote search anti display
Comparison of open source distributed link tracking
Wangxuegang video coding -- mediacodec coding and decoding
Use of [golang learning notes] package
02. Supplement of knowledge related to web page structure
What else do entrepreneurs need besides money? Exclusive interview with Mingyue Lake venture capital institutions