Saturday, February 25, 2012
Creating a database
I have the following in my input file:
CREATE TABLE admin
(
ID char(7),
Pwd varchar(32)
)
GO
How could I make it so that Pwd does not allow nulls and has a default value
of 'Password'?
hi Terry,
Terry Olsen wrote:
> When creating a database using OSQL -E -I CreateDatabase.sql
> I have the following in my input file:
> CREATE TABLE admin
> (
> ID char(7),
> Pwd varchar(32)
> )
> GO
> How could I make it so that Pwd does not allow nulls and has a
> default value of 'Password'?
SET NOCOUNT ON
USE tempdb
CREATE TABLE dbo.Admin (
ID varchar(7) NOT NULL ,
Pwd varchar(32) NOT NULL DEFAULT 'Password'
)
INSERT INTO dbo.Admin VALUES ('Andrea' , DEFAULT )
SELECT * FROM dbo.Admin
DROP TABLE dbo.Admin
--<--
ID Pwd
-- --
Andrea Password
please have a look at
http://msdn.microsoft.com/library/de...eate2_8g9x.asp
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtmhttp://italy.mvps.org
DbaMgr2k ver 0.12.0 - DbaMgr ver 0.58.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
-- remove DMO to reply
Tuesday, February 14, 2012
Create View with associated Index
I have inherited the following code from someone before me:
create view [ABC ] as
select T.*
,rtrim( cast([COL_1] as char( 2))
+ cast ([COL_3] as char( 3)) ) [ROLL01]
from [ABC_TABLE] T;
ROLL01 is primary key index; however as primary key it is made up of COL_1, COL_2, COL_3
I take it the index view is a separate object even though the same name is used as the primary key index? Because I would think this would greatly affect performance. Of course I do not like this anyway because of the documentation confusion.
In this view the [ROLL01] is an alias column name for the column that is being constructed with
,rtrim( cast([COL_1] as char( 2))
+ cast ([COL_3] as char( 3)) )
and has no implications on the primary key defined on the table.
I believe the person that did this was just trying to see the "composite key" as one single item.
The view is listing the contents of ABC_TABLE, with this additional column appended to the end of each row.