Transact-SQL Create Database And Create Table Examples

Tool : Microsoft SQL Server Management Studio (SSMS)

transact - conduct or carry out (business)

Create A Database Called [SampleDB]

/* Create a Database called [SampleDB] */

Create Database [SampleDB]

Create A Table Called [Departments]

/* Create a Table called [Departments] in the database [SampleDB] */

Use [SampleDB]
Go
Create Table [Departments]
(
 ID uniqueidentifier Primary Key,
 Name nvarchar(50),
 Location nvarchar(50)
);

Create A Table Called [Employees] With Foreign Key

/* Create a Table called [Employees] in the database [SampleDB] */

Use [SampleDB]
Go
Create Table [Employees]
(
 ID uniqueidentifier Primary Key,
 FirstName nvarchar(50),
 LastName nvarchar(50),
 Gender nvarchar(50),
 Salary int,
 DepartmentID uniqueidentifier Foreign Key references Departments(ID)
);

Table Relationships


Introduction to Transact SQL (T-SQL) using Microsoft SQL Server

張貼留言

0 留言