1 / 9

SQL Server Object Naming Conventions and Schema Management Guide

Learn the best practices for creating, altering, and dropping tables in SQL Server, including object naming conventions and schema ownership management. Understand the importance of using DBO schema and the implications of multiple table owners. Access examples and commands for creating databases and tables, as well as altering and dropping existing objects. Improve your SQL Server database management skills for maintaining consistent schemas across different environments.

sirvat
Download Presentation

SQL Server Object Naming Conventions and Schema Management Guide

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Creating and Altering Tablescis 407 Object NamesCreate StatementAlter statementDrop Statement

  2. GUI v ANSI/TSQL • ANSI works with all DBMSs • (e.g., oracle, db2, …) • Need a script to insure same DB schema on development, test, production systems • Easier (in my opinion)

  3. Object Names in SQL Server • [serverName.[DatabaseName.[SchemaName.]]]ObjectName • Schema Name --- ownership • Generally DBO – best to keep all relations in database owned by default DBO role. • If my login is given create table authority then that table owned by beard.mytable • If fred is db owner (created the database) a table he creates would be owned by fred.mytable • Confusing • Expensive: if relations in db owned by multiple owners than constantly must check access. • Stick to DBO by having anyone that needs to create tables have db sysadmin role.

  4. Database, server names • Select *from northwind.dbo.ordersselect *from northwind..orders (dbo default) • Can access relation on another server • Select *from myserver.northwind..orders • Server could be in PRC

  5. Create Database • CREATE DATABASE <database name>[on primary] ( [name = <‘logical file name’>,] [,SIZE=<size in kilo,.., terabytes>] [,MAXSIZE= <size in kilo,…,terabytes>] [,filegrowth=<kilo,…, terabytes>] ) ][log on [name = <‘logical file name’>] ] …..[collate <collation name> ]……

  6. CREATE DATABASE • Create database Accountingon (name = ‘accounting’, filename = ‘c:\program files\microsoft sql server\MSQL.1\mssql\data\accountingdata.mdf’., size = 10, maxsize = 50, fielgrowth = 5) • Log on (name = ‘accountingLog’, filename = ‘c:\program files\microsoft SQL server\ sqsql.1\mssql\data\accountingLog.ldf’, size = 5MB, maxsize = 25MB, filegrowth=5mb) • go

  7. Create Table (pg 128) • Create table customers (customerNo int identity(1,1) not null,customerName varchar(30) not null,address1 varchar(30) not null,address2 varchar(30) not null,….. • See example from web page • Exec sp_help customers • Tsql data types pg 12-15

  8. Alter Statement • Almost identical to create statement but change ‘create’ to ‘alter • Don’t want to have to delete relation and recreate (lose all that data!!)

  9. Drop statement • Drop customers • BE CAREFUL – no “are you sure” questions – it assumes you know what you are doing. • Use masterdrop database accounting

More Related