SQL语句创建数据库
1.create database dataname 这是创建数据库最简单的方法.数据库的各个属性都是默认.如数据库文件与日志文件存储目录.数据库大小等. 下面介绍下常用决定数据库属性的子句. on:简单理解为定义存储数据库文件的位置,看下面代码. filename:数据库的逻辑
1.create database dataname
这是创建数据库最简单的方法.数据库的各个属性都是默认.如数据库文件与日志文件存储目录.数据库大小等.
下面介绍下常用决定数据库属性的子句.
- on:简单理解为定义存储数据库文件的位置,看下面代码.
- filename:数据库的逻辑别名
- size:数据库初始大小
- maxsize:数据库初大容量
- filegrowth:数据库每次增加的容量.
- log on:简单理解为定义存储数据库日志文件的位置.
看创建代码:
- create database Accounting
- on(name='AccountingName',
- filename='F:/总结/Sql/创建和修改数据表/Accounting.mbdf',
- size=10mb,
- maxsize=50mb,
- filegrowth=5mb)
- log on(name='AccountingLog',
- filename='F:/总结/Sql/创建和修改数据表/Accounting.log',
- size=10mb,
- maxsize=50mb,
- filegrowth=5mb)
上面说到了 filegrowth:数据库每次增加的容量 结合代码来说.就是初始数据库大小为10mb.当数据库容量要超出时.他会自动增加5mb.这会就是15mb大小.最大到50mb
create database song on
(name=ktvdata,filename='D:/database/ktvdata.mdf',
size=8MB,maxsize=9MB,filegrowth=100KB)
log on
(name=ktvdata_log,filename='D:/database/ktvdata.ldf',
size=9MB,maxsize=10MB,filegrowth=100KB)
go
2. 使用ALTER DATABASE语句修改数据库
例4-3 将两个数据文件和一个事务日志文件添加到test数据库中。
程序清单如下:
ALTER DATABASE Test
ADD FILE
(NAME = Test1, FILENAME='c:/Program Files/Microsoft SQL Server/MSSQL/Data/test1.ndf', SIZE =
5MB, MAXSIZE = 100MB, FILEGROWTH = 5MB),
(NAME = Test2, FILENAME='c:/Program Files/Microsoft SQL Server/MSSQL/Data/test2.ndf', SIZE =
3MB, MAXSIZE = 10MB, FILEGROWTH = 1MB)
GO
ALTER DATABASE Test
ADD LOG FILE ( NAME = testlog1, FILENAME='c:/Program Files/Microsoft SQL
Server/MSSQL/Data/testlog1.ldf', SIZE = 5MB, MAXSIZE = 100MB, FILEGROWTH = 5MB)
GO
3、重命名test为demo
sp_renamedb 'test','demo'
4. 删除数据库: drop database song
go

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

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

Use the DataAccessObjects (DAO) library in C++ to connect and operate the database, including establishing database connections, executing SQL queries, inserting new records and updating existing records. The specific steps are: 1. Include necessary library statements; 2. Open the database file; 3. Create a Recordset object to execute SQL queries or manipulate data; 4. Traverse the results or update records according to specific needs.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.
