Chapter 4 QUERYING AND MODIFYING DATA 231 MAKING
Chapter 4 QUERYING AND MODIFYING DATA 231 MAKING DATA MODIFICATIONS As time passes, new data will no doubt need to be inserted, redundant data will need to be deleted, and existing data will need to be updated. Data may be modified with a few simple lines of T-SQL. Data modification is always necessary when working with real-life situations. Think, for example, of an employee changing houses. His address would need to be modified, which could be done using the UPDATE statement. Data modification is changing, deleting, or inserting data, and this section will teach you just that. Basically, there are three T-SQL statements that enable you to insert, delete, and update data; unsurprisingly, they are INSERT, DELETE, and UPDATE. Inserting Data into Tables Although there are many ways to insert data into an existing table, such as using the Enterprise Manager, this section deals with the primary coding method of using the INSERT statement. The syntax of the INSERT INTO statement can be summarized as follows: INSERT [INTO] table_or_view [(column_list)] VALUES .data_values The statement causes the data values to be inserted as one or more rows into the named table. Column list is a comma-separated list of column names that can be used to indicate the columns for which data is supplied. Remember, it s always a safe habit to practice modifying data on a test table. For these examples, use the table defined as follows: CREATE TABLE TestTable ( age int NULL, month varchar(8) NULL, phone varchar(15) NULL, gender varchar(7) NULL, haircolor varchar(14) NULL ) Now, to insert the data, enter the query as displayed in Figure 4.6.
For reliable and cheap web hosting services please check tomcat web hosting website.