SQL Server
T-SQL for Data DefinitionVu Tuyet Trinhtrinhvt-fit@mail.hut.edu.vnHanoi University of Technology1 MicrosoftMicrosoftOverview of Transact-SQLBased on AINSI SQL 92 standardComposing of three categoriesData Manipulation Language (DML)Data Definition Language (DDL)Data Control Language (DCL) Having some Microsoft specific extensionsBeyond relational data.net framework integration MicrosoftMicrosoftData Definition LanguageCreate used to create databases and their objects. Use allows you to specify the database you wish to work with within your DBMS.Alter used to modify the definition of it without deleting itDrop used to remove entire database objects MicrosoftMicrosoftOverview of Database Objects MicrosoftMicrosoftOutline√Data Definition LanguageManaging DatabasesData Types Managing Tables Managing other SQL Server Objects MicrosoftMicrosoftDatabases in SQL ServerDatabaseStoring data and other database objectsDatabase Snapshot Maintain historical data for report generationSafeguard data against administrative errorSafeguard data against user errorSQL Server Enterprise Edition MicrosoftMicrosoftCreating a New DatabaseFactors to considerDefault: Sysadmin, dbcreatorCreator becomes the ownerMaximum of 32,767 per serverFollow naming rules MicrosoftMicrosoftCreating a New DatabaseSome arguments: The name of the databaseThe size of the databaseThe files where the database will resideCREATE DATABASE SampleON PRIMARY ( NAME=SampleData, FILENAME='c:\Program Files\ \ \Data\Sample.mdf', SIZE=10MB, MAXSIZE=15MB, FILEGROWTH=20%) LOG ON ( NAME=SampleLog, FILENAME= 'c:\Program Files\ \ \Data\Sample.ldf', SIZE=3MB, MAXSIZE=5MB, FILEGROWTH=1MB)COLLATE SQL_Latin1_General_Cp1_CI_AS MicrosoftMicrosoftSetting & Viewing Database OptionsSet Database Options By Using:SQL Server Management StudioALTER DATABASE statementDatabase Option CategoriesAuto optionsCursor optionsRecovery optionsSQL optionsState options MicrosoftMicrosoftRetrieving Database InformationDetermining database properties by using the DATABASEPROPERTYEX FunctionSELECT DATABASEPROPERTYEX (‘pubs’,’useraccess’)SELECT DATABASEPROPERTYEX (‘pubs’,’recovery’)Using system stored procedures to display information about databases and its parameterssp_helpdbsp_helpdb database_namesp_spaceused [objname] [...]... Data-level consistency • Complex application development & deployment • Integration with structured data • Complex application development & deployment • Separate data management • Enterprise-scales only • Poor data streaming support • File size limitations • Highest cost per GB • Windows File Servers • NetApp NetFiler • EMC Centera • Fujitsu Nearline • SQL Server VARBINARY(MAX) BLOB Storage in SQL Server. .. File System Application TSQL (Same as SQL BLOB) Win32 Streaming APIs with T -SQL transactional semantics BLOB Data Consistency Integrated Manageability Back Up / Restore Administration Size limit is the file system volume size SQL Server Security Stack Microsoft DB BLOB Storage Vision File Stores / BLOB Stores Streaming Performance Depends on external store SQL BLOBs Remote BLOB Store... & Time bit, tinyint, smallint, int, bigint, numeric, decimal, smallmoney, money binary, varbinary, image Others Microsoft sql_ variant, timestamp, xml… User-defined Data Type Extending the SQL type system as Microsoft alias data types that consist of a single SQL Server system data type or structure of multiple data types having behaviors (CLR Type) New Date & Time Data Types DATE TIME... a Database SQL Server Enterprise Manager DROP DATABASE statement DROP DATABASE Northwind, pubs Restrictions on Dropping a Database Microsoft While it is being restored When a user is connected to it When publishing as part of replication If it is a system database Outline √ √ Data Definition Language Managing Databases Data Types Managing Tables Managing other SQL Server Objects... on external store SQL BLOBs Remote BLOB Store API FILESTREAM Depends on external store Link Level Consistency Data Level Consistency Integrated Management Non-local Windows File Servers Interop with External BLOB Stores Microsoft n/a n/a Post-2008 ... supports operations Microsoft Query() – returns XML from XQuery expression Value() – returns SQL type from XQuery Exist() – bool if XQuery exists Modify() – changes XML using XQuery Nodes() – shreds XML into relational data; think of it as a table valued split Storing Document & Multimedia Use File Servers Dedicated BLOB Store Store BLOBs in Database Application Application Application BLOBs BLOBs... NetFiler • EMC Centera • Fujitsu Nearline • SQL Server VARBINARY(MAX) BLOB Storage in SQL Server Use File Servers Application BLOB Store BLOBs in Database DB Application Dedicated BLOB Store Store BLOBs in DB + File System Application BLOB BLOB Application BLOB DB DB DB Remote BLOB Storage Microsoft SQL BLOB FILESTREAM Storage FILESTREAM Data Type Storage Attribute on VARBINARY(MAX) Unstructured... IsDescendant Parse GetDescendant GetLevel Reparent Tostring Spatial Data Types Storing geographic locations and shapes such as landmarks, roads, building, … Based on vector model specified in Well-Known Text (WKT) or WellKnown Binary (WKB) format (recommended by Open Geospatial Consortium) Microsoft Geography & Geometry Data Type Microsoft Performing Spatial Operations Both types provide static... Automatic validation of XML documents Automatic shredding of the XML data to support efficient querying and updating of the content Searching and updating via an implementation of XQuery and XML-DML Microsoft Using XML Data Type Declaration is (mostly) like other data types Usage is (mostly) like other data types Table: CREATE TABLE T(MyXml XML) Variable: DECLARE @MyXml XML Query:... Some of the limitations: Microsoft Does not support converting to text or ntext Cannot be compared or sorted So, no GROUP BY, PRIMARY KEY, etc Cannot be used as a parameter to any scalar, built-in functions other than ISNULL, COALESCE, and DATALENGTH Stored semantically The order of attributes and insignificant white spaces are not preserved Creating XML Data Converting Strings Bulk . T -SQL for Data DefinitionVu Tuyet Trinhtrinhvt-fit@mail.hut.edu.vnHanoi University of Technology1 MicrosoftMicrosoftOverview of Transact -SQL Based. DatabasesData Types Managing Tables Managing other SQL Server Objects MicrosoftMicrosoftDatabases in SQL Server DatabaseStoring data and other database objectsDatabase