Ds Labsession 5
Ds Labsession 5
Ds Labsession 5
DATABASE SYSTEMS
This query will show the records of top 10 employees in the database.
Any thing
On this area*/
USING LITERALS
Literals are letters, numerals or symbols that are used as specific value in a result set to increase
readability. The usage is illustrated in the following examples:
The ‘companyname: ‘ is literal in the above queries but result will be different for both queries.
INSERT STATEMENT
The insert statement adds rows to a table. The syntax is:
Insert is used with the values clause to add rows. When inserting rows, consider the following points:
• Use the column list to specify the columns that will store each incoming value. If values for all
columns are supplied then column list is optional.
• The actual values to be inserted to go in the values_list.
• If you have provided column names in the column_list then each and every values after values
clause (i.e. values_list) should correspond to the column list. If column_list is not provided
then values for all the table fields must be supplied.
• Data should be inserted in correct format. For example, characters or date must be enclosed
in single quotation marks.
• Into clause is also optional.
• Insert statement will fall if it violates an existing constraint or rule.
The following example inserts a new record in the employees table. INSERT
INTO CUSTOMERS
VALUES(‘ABCD’, ’JOHN ENTERPRISES’, ‘JOHN MICHAEL’, ‘OWNER’, ‘760 MASTER STREET ’, ‘BERGS’,
‘AREA’, ‘G785’,’CANADA’, ’(603) 588-8980’, ‘(603) 322-7490’)
List only the column names for the data that you are supplying in the insert statement.
Enter a Null value explicitly by typing Null without single quotation marks.
The following example adds the last name in the table employees.
(FIRSTNAME, LASTNAME)
VALUES ('MICHAEL','JOHN')
UPDATE STATEMENT
This statement modifies the existing data. Syntax is:
UPDATE <TABLE_NAME>
SET <COLUMN_NAME> = <EXPRESSION>
WHERE <SEARCH_CONDITION>
Use update statement to change single rows, group of rows or all of the rows in a table. Guidelines for
this statement are as under.
columns. The following example adds 1500 in the salary of all employees
UPDATE EMPLOYEES
WHERE EMPLOYEEID = 1
DELETE STATEMENT
Use delete statement to remove one or more rows from a table. Syntax is:
WHERE <SEARCH_CONDITION>
Important points for DELETE statement is, SQL server deletes all rows from a table unless you include a
where clause, so do remember to add the where clause, otherwise all the data will be deleted.
WHERE LASTNAME='JOHN'
The above example will delete only the row with last name as john.
Note: try to avoid deleting existing records. First add a record and then apply deletion to that particular
record.
EXERCISE:
Run the example queries and observe the results.
a query that selects starting 20 percent records of the all records of table customers whose
contact title must be sales representative and country must be Germany and contact name
must have ‘N’ as third character. Sort the result by contact name.
Insert at least 8 records in the each table of your named database you made in previous lab
session.
Insert using partial data insertion the order id 100 and order name chocolate in table order.
Modify the table employees of Northwind database by setting salary as triple plus hundred for
employee id 1 to 10.
Set the first name of employee as john in the employees table of Northwind database whose
id is 1.
Delete any one record (row) of any table and write query in the manual.
ff