IT tutorials
 
Technology
 

SQL Server 2012 : Creating Tables and Other Objects - Transact-SQL (T-SQL) Primer

12/14/2013 2:30:43 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

Before you learn how to create various objects within the database, it is important to review the general constructs of the T-SQL language. T-SQL is Microsoft’s version of the Structured Query Language (SQL) programming language. SQL is a declarative programming language, which means that the SQL code describes what information should be returned, or what the end goal is, as opposed to how to go about retrieving information or doing some work. The SQL language contains categories of statements. These categories are Data Definition Language (DDL), Data Manipulation Language (DML), and Data Control Language (DCL).

Data Definition Language (DDL)

DDL statements describe the creation or modification of objects within the database server. In our previous example using SSMS, you noticed that when you created the SmartCommunityBank database, SSMS really executed a T-SQL script using the CREATE DATABASE DDL statement. The script that SSMS generates is sometimes more verbose than what is required at a minimum. For example, the minimum code that is needed to create a database is as follows:

USE [master]
GO
CREATE DATABASE [VetClinic]
GO

This will create a database named VetClinic using default values .

DDL statements also deal with the modification of objects. An example of modifying an existing object using the ALTER DDL statement is as follows:

USE [master]
GO
ALTER DATABASE VetClinic
SET RECOVERY FULL
GO

The previous example changes the database recovery mode to FULL for an existing database.

DDL statements also apply to the creation of security principals and objects. For example, if you wanted to create a new SQL Server login named ReceptionistUser, you would execute the following script:

USE [master]
GO
CREATE LOGIN ReceptionistUser WITH PASSWORD='hj2(*h2hBM!@jsx'
GO

Data Manipulation Language (DML)

DML statements read and modify the actual data within the database. For example, assume you created the following table using DDL statements within the VetClinic database:

USE [VetClinic]
GO
CREATE TABLE [Pets]
(pet_id      INT  PRIMARY KEY,
pet_name    VARCHAR(50)  NOT NULL,
pet_weight   INT           NOT NULL)
GO

Now, let’s add some data to the Pets table using the INSERT DML statement. The code follows:

USE [VetClinic]
GO
INSERT INTO Pets VALUES
 (1,'Zeus',185),
(2,'Lady',155),
(3,'Deno',50)
GO

If you want to query the data, you can use the SELECT DML statement as follows:

SELECT * FROM Pets

If you execute this statement within SSMS, it will return the three pets defined previously in the results grid. Other DML statements include UPDATE and DELETE, which are two important actions to perform against data.

Data Control Language (DCL)

DCL statements control access to data. For example, if you wanted to give SELECT access to ReceptionistUser, you could use the GRANT DCL statement as follows:

USE [VetClinic]
GO
GRANT SELECT ON Pets TO ReceptionistUser
GO

Other DCL statements include REVOKE and DENY. These are used to either remove a previously granted permission or deny someone access to a particular object. Note that DENY takes precedence over GRANT at a higher scope. For example, ReceptionistUser is granted SELECT on the Pets table. This enables ReceptionistUser to read all the columns within the table. The administration could DENY that user specific access to a column, and even though ReceptionistUser has SELECT access for the entire table, the specific column would not be available.

 
Others
 
- SQL Server 2012 : Creating Tables and Other Objects - Navigating the Object Explorer Tree
- SQL Server 2012 : Creating Tables and Other Objects - Navigating the Object Explorer Tree
- Using the Windows PowerShell in an Exchange Server 2007 Environment : Using EMS to Do Administrative Server Tasks
- Using the Windows PowerShell in an Exchange Server 2007 Environment : Using EMS to Do Administrative Mailbox Tasks
- Using the Windows PowerShell in an Exchange Server 2007 Environment : Managing Cmdlets
- Using the Windows PowerShell in an Exchange Server 2007 Environment : Creating Your Own Cmdlet
- PowerShell for Microsoft SharePoint 2010 : Special Operators
- PowerShell for Microsoft SharePoint 2010 : Type Operators
- PowerShell for Microsoft SharePoint 2010 : Redirection Operators
- PowerShell for Microsoft SharePoint 2010 : Logical Operators
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us