🔧 How to Create a Database in Sybase (Including Devices)
If you're used to working with Microsoft SQL Server, creating a database in Sybase ASE (Adaptive Server Enterprise) can feel quite different. One of the key distinctions is that Sybase requires you to explicitly create devices before you can create a database.
This guide walks you through the full process: from creating devices to creating the database and setting the correct owner.
🧱 What Are Devices in Sybase?
In Sybase ASE:
-
A device is a physical file (or raw partition) where data is stored.
-
You typically separate your data device (for tables, indexes, etc.) and log device (for transactions).
-
This allows for better performance and recovery management.
📂 Step 1: Create the Devices
You must first create the data and log devices using disk init.
-- Create a data device (e.g., 100 MB)
disk init
name = "datadev1",
physname = "/sybase/data/datadev1.dat",
size = 51200
-- Create a log device (e.g., 50 MB)
disk init
name = "logdev1",
physname = "/sybase/data/logdev1.dat",
size = 25600
-- Optionally, add another data device for later growth
disk init
name = "datadev2",
physname = "/sybase/data/datadev2.dat",
size = 70000
⚠️ Note: Adjust the file paths and sizes according to your server setup.
🗃️ Step 2: Create the Database
Now that your devices are ready, create the database and allocate space.
USE master
GO
-- Initial database creation
CREATE DATABASE mydatabase
ON datadev1 = 1000
LOG ON logdev1 = 250
GO
-- Extend the database on a second data device
ALTER DATABASE mydatabase
ON datadev2 = 1000
GO
-- Add more space as needed
ALTER DATABASE mydatabase
ON datadev2 = 348
GO
💡 The numbers (e.g.,
1000) represent the number of 2KB pages.
1000 pages = ~2MB. So adjust based on how much space you need.
👤 Step 3: Set the Database Owner
It's a good practice to set the database owner to sa to ensure full permissions — especially for automation jobs or admin tasks.
USE mydatabase
GO
EXEC sp_changedbowner 'sa'
GO
✅ Summary
-
✅ Create devices with
disk init -
✅ Create the database using
CREATE DATABASE ... ON ... LOG ON ... -
✅ Extend the database with
ALTER DATABASE -
✅ Set the owner to
sawithsp_changedbowner
Comments
Post a Comment