SlideShare a Scribd company logo
4SQL SERVER: MANIPULATING A DATABASE
Manipulating a DatabaseHOW TO MAKE CHANGES TO THE STRUCTURE OF THE DATABASE?A Database table can be defined by:The Fields(Columns) and their propertiesRecords(Rows) and their propertiesIt is important to understand clearly that the records are user-entries into a database table. Fields are created during the design phase of a databaseNow let us see how to carry out the changes to the above defined properties of a database.
Modifying the ColumnsThe Columns or fields in a database table can be easily modified using the ‘alter table’ command, which comes under DDL(Data Definition Language)What are the changes that can be made to a field?Add a new filed
Edit an existing field
Remove a field from table
Add a constraint on the data that a field can hold (will be dealt with later)Now lets see how these actions can be performed in SQL Server 2008
Add a new fieldThe SQL DDL command ‘alter table…add’ is used for adding a new fieldalter table <tableName> add <field name> <field type>;For example, consider the following animal database used by ‘MetaZooa’  Zoo, for maintaining the details of the animals in the zoo.
Add a new fieldNow, suppose the MetaZooa corp. decides to construct another Zoo beside the old one and divide the animals between the zoos. Then, the database of MetaZooa must contain details of the zoo-number also.
Add a new fieldSteps to add a new fieldConsidering the previous example, the command will be:alter table MetaZooDBaddZoo int;Run this command using ‘Go’ command.
Modifying an existing fieldNow, suppose MetaZooa decides to that ‘Zoo’ contains the Zoo Name rather than the number ‘1’ or ‘2’, we need to modify the field type.The Command is:alter table MetaZooDBalter column Zoo varchar(15);Run this command using ‘Go’ command.But we might have complications…
Modifying an existing fieldProblem:The Data contained in the field that is to be modified must be compatible with the destination data-type. Other-wise, conversion cannot be carried outCompatibility ChartSourceDestinationSourceVarchar(Strings)Integers (Int)Varchar (Strings)Integers (Int)Legend:Conversion Allowed:Conversion NOT allowed:Decimals (Float)Date and Time
Modifying an existing fieldSourceDestinationSourceVarchar (Strings)Decimals (Float)Date and TimeIntegers (Int)Decimals (Float)Date and Time
Remove a column from tableThe DDL command ‘alter table’ in conjunction with the ‘drop column’ is used to delete a column/field from a user table. The Syntax is:alter table <table_name> drop column <column_name>For example, consider the follwingDreamTable. Suppose the User wishes to remove the DreamType field… alter table DreamTable drop column DreamType
Deleting a RowA Record is a row in a table. For example, consider a fish database maintained by a ‘Eden-Lake Ecology farm’. Now, suppose the people go on a shark-mania and the sharp population vanished from the lake, it is meaningful for the Eco farm to remove its entry from the database.Now let us see the command

More Related Content

PPTX
SQL(DDL & DML)
DOCX
Ddl commands
PDF
Data manipulation language
PPTX
Oracle: DML
PDF
Export Data using R Studio
PPT
SQL Tutorial - How To Create, Drop, and Truncate Table
PPT
Creating a database
SQL(DDL & DML)
Ddl commands
Data manipulation language
Oracle: DML
Export Data using R Studio
SQL Tutorial - How To Create, Drop, and Truncate Table
Creating a database

What's hot (16)

PPT
Sql basics and DDL statements
PPT
MySQL lecture
PDF
Import and Export Excel Data using openxlsx in R Studio
PDF
Import and Export Excel files using XLConnect in R Studio
PPTX
SQL-Alter Table, SELECT DISTINCT & WHERE
DOCX
Procedure To Store Database Object Size And Number Of Rows In Custom Table
PPTX
Oracle: DDL
PDF
Stata tutorial university of princeton
PPTX
MySQL Essential Training
PPT
PDF
Manipulating Data using DPLYR in R Studio
PDF
Database Architecture and Basic Concepts
PDF
Import Data using R
PDF
Sql smart reference_by_prasad
Sql basics and DDL statements
MySQL lecture
Import and Export Excel Data using openxlsx in R Studio
Import and Export Excel files using XLConnect in R Studio
SQL-Alter Table, SELECT DISTINCT & WHERE
Procedure To Store Database Object Size And Number Of Rows In Custom Table
Oracle: DDL
Stata tutorial university of princeton
MySQL Essential Training
Manipulating Data using DPLYR in R Studio
Database Architecture and Basic Concepts
Import Data using R
Sql smart reference_by_prasad
Ad

Viewers also liked (20)

PPTX
Control Statements in Matlab
PPT
How To Make Pb J
PPTX
Txomin Hartz Txikia
PPTX
MS SQL SERVER: Programming sql server data mining
PPTX
Drc 2010 D.J.Pawlik
PPTX
MS Sql Server: Deleting A Database
KEY
Kidical Mass Presentation
PPTX
R Statistics
PPTX
Data Applied: Association
PPTX
Data Mining The Sky
PPTX
Communicating simply
PPTX
Knowledge Discovery
PPTX
SQL Server: BI
PPTX
Bernoullis Random Variables And Binomial Distribution
ODP
Presentazione oroblu
PPTX
Pentaho: Reporting Solution Development
DOC
建築師法修正草案總說明
XLSX
PPTX
MS Sql Server: Doing Calculations With Functions
PPT
Festivals Refuerzo
Control Statements in Matlab
How To Make Pb J
Txomin Hartz Txikia
MS SQL SERVER: Programming sql server data mining
Drc 2010 D.J.Pawlik
MS Sql Server: Deleting A Database
Kidical Mass Presentation
R Statistics
Data Applied: Association
Data Mining The Sky
Communicating simply
Knowledge Discovery
SQL Server: BI
Bernoullis Random Variables And Binomial Distribution
Presentazione oroblu
Pentaho: Reporting Solution Development
建築師法修正草案總說明
MS Sql Server: Doing Calculations With Functions
Festivals Refuerzo
Ad

Similar to MS Sql Server: Manipulating Database (20)

DOCX
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
PPTX
Database management system by Neeraj Bhandari ( Surkhet.Nepal )
PPTX
Unit - II.pptx
PPTX
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
PPTX
Introduction to SQl Commands.pptxhhjhvvb
PPTX
SQL commands in database managemant systems
PPTX
introdution to SQL and SQL functions
PPTX
Database Languages power point presentation
PPTX
DBMS UNIT-2.pptx ggggggggggggggggggggggg
PPTX
SQL Queries Information
PPTX
SQL: Data Definition Language(DDL) command
PPTX
Lecture - MY-SQL/ SQL Commands - DDL.pptx
PDF
DBMS.pdf
PPTX
SQL commands in database management system
PPTX
lovely
DOCX
SQL Tutorial for BCA-2
PPTX
SQL.pptx for the begineers and good know
PPTX
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
PPTX
Data base
DOC
Oracle SQL AND PL/SQL
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Database management system by Neeraj Bhandari ( Surkhet.Nepal )
Unit - II.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
Introduction to SQl Commands.pptxhhjhvvb
SQL commands in database managemant systems
introdution to SQL and SQL functions
Database Languages power point presentation
DBMS UNIT-2.pptx ggggggggggggggggggggggg
SQL Queries Information
SQL: Data Definition Language(DDL) command
Lecture - MY-SQL/ SQL Commands - DDL.pptx
DBMS.pdf
SQL commands in database management system
lovely
SQL Tutorial for BCA-2
SQL.pptx for the begineers and good know
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
Data base
Oracle SQL AND PL/SQL

More from DataminingTools Inc (20)

PPTX
Terminology Machine Learning
PPTX
Techniques Machine Learning
PPTX
Machine learning Introduction
PPTX
Areas of machine leanring
PPTX
AI: Planning and AI
PPTX
AI: Logic in AI 2
PPTX
AI: Logic in AI
PPTX
AI: Learning in AI 2
PPTX
AI: Learning in AI
PPTX
AI: Introduction to artificial intelligence
PPTX
AI: Belief Networks
PPTX
AI: AI & Searching
PPTX
AI: AI & Problem Solving
PPTX
Data Mining: Text and web mining
PPTX
Data Mining: Outlier analysis
PPTX
Data Mining: Mining stream time series and sequence data
PPTX
Data Mining: Mining ,associations, and correlations
PPTX
Data Mining: Graph mining and social network analysis
PPTX
Data warehouse and olap technology
PPTX
Data Mining: Data processing
Terminology Machine Learning
Techniques Machine Learning
Machine learning Introduction
Areas of machine leanring
AI: Planning and AI
AI: Logic in AI 2
AI: Logic in AI
AI: Learning in AI 2
AI: Learning in AI
AI: Introduction to artificial intelligence
AI: Belief Networks
AI: AI & Searching
AI: AI & Problem Solving
Data Mining: Text and web mining
Data Mining: Outlier analysis
Data Mining: Mining stream time series and sequence data
Data Mining: Mining ,associations, and correlations
Data Mining: Graph mining and social network analysis
Data warehouse and olap technology
Data Mining: Data processing

Recently uploaded (20)

PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Modernizing your data center with Dell and AMD
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Approach and Philosophy of On baking technology
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPT
Teaching material agriculture food technology
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Chapter 3 Spatial Domain Image Processing.pdf
Machine learning based COVID-19 study performance prediction
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
NewMind AI Monthly Chronicles - July 2025
Encapsulation_ Review paper, used for researhc scholars
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Modernizing your data center with Dell and AMD
20250228 LYD VKU AI Blended-Learning.pptx
Approach and Philosophy of On baking technology
The Rise and Fall of 3GPP – Time for a Sabbatical?
Digital-Transformation-Roadmap-for-Companies.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Network Security Unit 5.pdf for BCA BBA.
CIFDAQ's Market Insight: SEC Turns Pro Crypto
NewMind AI Weekly Chronicles - August'25 Week I
Teaching material agriculture food technology
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Understanding_Digital_Forensics_Presentation.pptx

MS Sql Server: Manipulating Database

  • 2. Manipulating a DatabaseHOW TO MAKE CHANGES TO THE STRUCTURE OF THE DATABASE?A Database table can be defined by:The Fields(Columns) and their propertiesRecords(Rows) and their propertiesIt is important to understand clearly that the records are user-entries into a database table. Fields are created during the design phase of a databaseNow let us see how to carry out the changes to the above defined properties of a database.
  • 3. Modifying the ColumnsThe Columns or fields in a database table can be easily modified using the ‘alter table’ command, which comes under DDL(Data Definition Language)What are the changes that can be made to a field?Add a new filed
  • 5. Remove a field from table
  • 6. Add a constraint on the data that a field can hold (will be dealt with later)Now lets see how these actions can be performed in SQL Server 2008
  • 7. Add a new fieldThe SQL DDL command ‘alter table…add’ is used for adding a new fieldalter table <tableName> add <field name> <field type>;For example, consider the following animal database used by ‘MetaZooa’ Zoo, for maintaining the details of the animals in the zoo.
  • 8. Add a new fieldNow, suppose the MetaZooa corp. decides to construct another Zoo beside the old one and divide the animals between the zoos. Then, the database of MetaZooa must contain details of the zoo-number also.
  • 9. Add a new fieldSteps to add a new fieldConsidering the previous example, the command will be:alter table MetaZooDBaddZoo int;Run this command using ‘Go’ command.
  • 10. Modifying an existing fieldNow, suppose MetaZooa decides to that ‘Zoo’ contains the Zoo Name rather than the number ‘1’ or ‘2’, we need to modify the field type.The Command is:alter table MetaZooDBalter column Zoo varchar(15);Run this command using ‘Go’ command.But we might have complications…
  • 11. Modifying an existing fieldProblem:The Data contained in the field that is to be modified must be compatible with the destination data-type. Other-wise, conversion cannot be carried outCompatibility ChartSourceDestinationSourceVarchar(Strings)Integers (Int)Varchar (Strings)Integers (Int)Legend:Conversion Allowed:Conversion NOT allowed:Decimals (Float)Date and Time
  • 12. Modifying an existing fieldSourceDestinationSourceVarchar (Strings)Decimals (Float)Date and TimeIntegers (Int)Decimals (Float)Date and Time
  • 13. Remove a column from tableThe DDL command ‘alter table’ in conjunction with the ‘drop column’ is used to delete a column/field from a user table. The Syntax is:alter table <table_name> drop column <column_name>For example, consider the follwingDreamTable. Suppose the User wishes to remove the DreamType field… alter table DreamTable drop column DreamType
  • 14. Deleting a RowA Record is a row in a table. For example, consider a fish database maintained by a ‘Eden-Lake Ecology farm’. Now, suppose the people go on a shark-mania and the sharp population vanished from the lake, it is meaningful for the Eco farm to remove its entry from the database.Now let us see the command
  • 15. Deleting a RowDeleting a row:For deleting a row, it must be identified using a ‘distinguishing’ attribute which lets the computer tell it apart from other records.For the above example, the record can be identified using:The Primary key (FishID)Or any other special attribute (like Fish Name).But in general, always use the Primary Key, as it is best suited for uniquely identifying a record in a database table.NOTE: Strings/Date data-types must be encapsulated within single quotesdelete from <table_name> where <condition>delete from EdenFishTable where FishID = ‘23H’
  • 16. Summary4. Manipulating a Database Adding Fields
  • 23. Delete from..whereVisit more self help tutorialsPick a tutorial of your choice and browse through it at your own pace.The tutorials section is free, self-guiding and will not involve any additional support.Visit us at www.dataminingtools.net